Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(web): the sidebar compiles with no manual memoization #20396

Mergedjuliusmarmingemerged 2 commits intochatview-split/chat-shortcuts fromrefs/pull/20396/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

The native React Compiler skipped Sidebar.tsx with 15 bailouts, so none of the sidebar was compiled. This PR does more than get it compiling: Sidebar joins the strict REACT_COMPILED_FILES list with no manual memoization (103 useMemo/useCallback removed) and none of the compiler's effect rules broken. There are no disable comments.

Why removing memos had to change structure. A plain removal still compiled, but 33 values lost their caching, including the dnd-kit sorting strategy, the drag handlers and the thread partition. Inside the 2,800-line component the compiler couldn't prove that the local maps and arrays stayed unchanged. Hook return values reach the caller frozen, so the derivations moved into hooks:

  • useSidebarThreads reads its own inputs (thread shells, the working-shelf setting, the minute clock, the snooze-wake timer, the shelf state). It returns the partition, the shelves, ordered keys, threadByKey, sectionByThreadKey and the pinned/active key maps.
  • partitionSidebarThreads is a pure module function. It takes clockKey (nowMinute plus the snooze wake tick) as an explicit input. Before, the minute tick only ran because nowMinute happened to be listed in a memo's deps.
  • useSidebarLookups builds the project and environment maps.
  • resolveDraggedOrders computes drag previews, with a NO_DRAGGED_ORDERS constant for when nothing is dragging.

I checked the compiled output for each value dnd-kit and the rows depend on:

  • dndModifiers, the sensor options and the rename/drag-cancel handlers are computed once.
  • sortableIds is cached on the list items.
  • sidebarSortingStrategy and dndCollisionDetection are cached on the drag state and the thread maps.
  • The drag start and end handlers are cached on the section and thread maps.
  • Each settle, snooze and pin handler is cached on its own command.

Effects that copied state became render-time logic:

  • The search highlight resets when the result list changes.
  • The snooze menu closes when its button goes away.
  • The optimistic drop hold releases in the same frame as the drop.
  • The settled-tail reset lives in the threads hook.
  • Clearing the selection happens where the scope changes, including the auto-correct when a scoped project disappears.
  • WorkingDuration keeps its clock in state, ticked by its interval, instead of calling Date.now() during render.

Removed: the change-request snapshot props and subscription that rows never read, plus isInFlight, showHoverActions and other unused locals.

Also from the compile pass:

  • SidebarDraftBlock reads the route-draft row from the draft maps it subscribes to.
  • Settle and snooze release their in-flight guard right after the await, since those commands settle into results and never throw.

Tests: reactCompiledFiles, the Sidebar.* logic, drag, motion, pointer and snooze tests, and ThreadStatusIndicators (327 pass).

Stack progress

LayerChatView linesChatView component bodyCompiler on ChatViewFiles held to strict compiler lint
main11,66010,007crashes (internal error)0
#20161 pending approvals and questions hook11,2229,624crashes (internal error)0
#20164 terminal drawer and panel file10,6149,624crashes (internal error)0
#20289 one terminal open/close hook10,4669,481crashes (internal error)0
#20292 compile-required lint list10,4669,481crashes (internal error)2
#20294 pending hook compiles10,4669,481crashes (internal error)3
#20296 /usage-limits panel hook10,3979,416crashes (internal error)4
#20304 queued-message editing hook10,1729,200crashes (internal error)5
#20308 linked pull request hook10,0789,106crashes (internal error)6
#20309 proactive panel hook9,9508,984crashes (internal error)7
#20312 agent-opened previews hook9,8558,890crashes (internal error)8
#20315 right panel close hook9,7438,779crashes (internal error)9
#20316 worktree setup hook9,6608,695crashes (internal error)10
#20321 two onSend phases split out9,6608,613crashes (internal error)10
#20340 compiler no longer crashes on ChatView9,6478,599skips (32 reasons)10
#20379 ChatView compiles9,6168,469compiles11
#20380 re-render fixes from profiling9,6618,514compiles11
#20392 provider pushes keep identity9,6288,481compiles11
#20393 keyboard shortcuts command map9,3408,265compiles13
→ #20396 Sidebar compiles, no manual memos9,3408,265compiles14
#20397 ChatComposer compiles9,3408,265compiles14
#20401 project script editing hook9,1108,049compiles15
#20402 MessagesTimeline compiles9,1108,049compiles16
#20418 ChatView strict: no memos, no sync effects8,9017,855compiles17

Measured with the native React Compiler (oxc-transform-react) on each layer's ChatView.tsx. "Crashes" means it hit an internal codegen error and left ChatView uncompiled; "skips" means it reported reasons it could not compile it. Strict files must compile with no bailouts, no manual memoization and no effect-rule violations; lint and reactCompiledFiles.test.ts enforce it.

🤖 Generated with Claude Code (Claude Opus 5.5)


Devin Review
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. juliusmarminge added labelsmacroscope-review

    3. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ⚠️ The latest CI run did not produce a thread transfer result for c58c9ea.

      This comment will update automatically after the next completed run.

    4. juliusmarminge changed the title

    5. @@ -2716,14 +2908,13 @@
      27162908 );
      2717- const threadSearchResults = useMemo(
      2718- () =>
      2719- searchSidebarThreads(
      2720- searchableThreads,
      2721- threadSearchQuery,
      2722- new Set(threadSearchMatchByKey.keys()),
      2723- ),
      2724- [searchableThreads, threadSearchQuery, threadSearchMatchByKey],
      2909+ const threadSearchResults = searchSidebarThreads(
      2910+ searchableThreads,
      2911+ threadSearchQuery,
      2912+ new Set(threadSearchMatchByKey.keys()),
      27252913 );
      27262914 const threadSearchResultOrderKey = threadSearchResults
      27272915 .map((thread) => scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)))
      27282916 .join("\0");
      27292917
      2918+ // The highlight belongs to one result list; a new list starts at the top.
      2919+ const activeSearchResultIndex =
      2920+ searchHighlight.orderKey === threadSearchResultOrderKey ? searchHighlight.index : 0;
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium components/Sidebar.tsx:2920

      After highlighting result 5 in list A, switching to list B and back to A makes result 5 active again, so pressing Enter opens the stale selection instead of the first result. activeSearchResultIndex only derives a temporary zero for a different orderKey; it never updates searchHighlight. Persist the reset when the result-list order changes.

      +  useEffect(() => {
      +    setSearchHighlight((current) =>
      +      current.orderKey === threadSearchResultOrderKey
      +        ? current
      +        : { orderKey: threadSearchResultOrderKey, index: 0 },
      +    );
      +  }, [threadSearchResultOrderKey]);
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/web/src/components/Sidebar.tsx around line 2920:
      
      After highlighting result 5 in list A, switching to list B and back to A makes result 5 active again, so pressing Enter opens the stale selection instead of the first result. `activeSearchResultIndex` only derives a temporary zero for a different `orderKey`; it never updates `searchHighlight`. Persist the reset when the result-list order changes.
    6. Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — This is a broad production Sidebar/compiler refactor that changes state ownership, render timing, drag-and-drop behavior, snooze and optimistic updates, and search/navigation handling across a large component. An unresolved Medium-severity finding also identifies stale search selection state, so human review is needed.

      Needs human approval because:

      • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    7. juliusmarminge merged this2de98f0

    8. juliusmarminge closed this

Sign in to join this conversation.