Skip to content

Render only the changed sidebar row when one thread changes - #7608

Merged
ymichael merged 3 commits into
mainfrom
bb/fix-ask-user-question-typing-lag-with-many-threa-thr_fhvv59u7d7
Nov 16, 2026
Merged

ymichael merged 3 commits into
mainfrom
bb/fix-ask-user-question-typing-lag-with-many-threa-thr_fhvv59u7d7

Conversation

@ymichael

@ymichael ymichael commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

A change to one thread re-rendered every mounted sidebar row, along with each row's context-menu, dropdown and tooltip subtree. Rows subscribed to whole-sidebar collections:

  • the sidebar entries Map context;
  • SidebarProjectsContext, used for a project-name lookup;
  • useThreadSelectionMenu → useSidebarData();
  • the title-mention resources context (threadById).

On top of that, useSidebarThreads rebuilt every thread DTO whenever those resources changed, and the thread-list model rebuilt every tree node, DnD state object and sortable id array, so memo(ThreadRow) never held. This came out of the Discord report of Ask User Question typing lag with ~500 threads. Typing in the question form did not reproduce (0 sidebar renders on main and on v0.49.0); the sidebar fan-out the reporter's agent described did. Repro and numbers are in the issue draft in bb thread thr_fhvv59u7d7.

What changed

  • apps/app/src/lib/sidebar-thread-entries.ts: the provider and context are gone. A per-QueryClient store reads the sidebar-navigation and archived caches, falling back to the cached bootstrap like the query's placeholderData, and notifies only the thread ids whose entry changed. useSidebarThreadEntry is a keyed useSyncExternalStore. useSidebarThreadActions and split-drag mentions look entries up when they run, not during render.
  • plugin-sidebar-hooks.ts: thread DTOs are cached on their entry plus the derived host name and display title.
  • ThreadTitleMentions.tsx: ThreadTitleMentionsContent reads the resources with conditional use() only when the title can contain a mention. A stable getter context lets useSidebarThreadSplit resolve the drag label when the drag starts.
  • thread-list plugin:
    • tree nodes, items, environment groups and section groups are reused when their thread and children are unchanged;
    • collapsedThreadIds no longer depends on threads;
    • rows get a project-name map instead of all projects;
    • selection targets live in the selection store;
    • sectionDnd and SortableContext ids stay stable while unchanged.
  • DnD behavior change: while no drag is active, a reorder keeps the previous sortable id order until a drag starts. dnd-kit only uses that order during a drag. The pinned ids, which also drive render order, always update.
  • No wire, CLI or public SDK changes. Plugin SDK hook behavior is unchanged apart from fewer re-renders.

How you verified

Same 501-thread fixture on a pnpm start:worktree instance, react-dom/profiling build, fiber-counting hook; 39 sidebar rows mounted.

Scenario main This PR
Rename another thread 39 rows, 3,568 renders, 16–19 ms target row only*, 533 renders, 6–8 ms
Another thread runs a turn (and moves to the top) 39 rows, 10,529 renders, 40–41 ms target row only*, 1,277 renders, 15 ms
Type 20 chars in an Ask User Question answer 0 rows, 1,070 renders, 7 ms 0 rows, 1,070 renders, 7 ms

*For a rename of a child thread, its parent row also re-renders, because it shows its children's rollup.

Tests:

  • New PluginThreadList.row-isolation.test.tsx uses the real thread-list plugin with the app's title-mention resources. It checks that a thread update renders only that thread's row, that typing in a question form renders no row, and that a row still moves when its sort order changes while idle. The first check fails on main with 59 rows.
  • sidebar-thread-entries.test.tsx: changing one entry re-renders only that entry's consumers; the cached bootstrap is read before the query has data.
  • useSectionThreadDnd.projection.test.tsx: the pinned order follows a pin reorder while idle. This fails without the pinned exception.
  • Rebased on main, which now includes Add a real-browser render invariant suite to CI #7601. This PR turns on the render invariants "renaming thread X re-renders no sidebar row but X's" and "a turn in thread X re-renders no sidebar row but X's", so CI runs them. They fail on main, where all 41 measured sidebar rows re-render, and pass on this branch.
  • pnpm exec turbo run test typecheck lint --filter=bb-plugin-thread-list, turbo run typecheck lint --filter=@bb/app, and targeted @bb/app sidebar, plugin-title, overlay and title-mention tests pass.
  • Manual QA in the built app: after a turn reordered the list while idle, I dragged that row into a section and dragged a pinned thread above another. Both persisted (checked with bb thread list) and the pinned order updated live.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 3 commits November 16, 2026 13:33
A rename, or a push from another thread's turn, re-rendered every mounted
sidebar row: each row subscribed to whole-sidebar collections, and the
thread-list model rebuilt every node, so memo(ThreadRow) never held.

- Replace the sidebar entries Map context with a per-QueryClient store fed
  by the query cache, with per-thread useSyncExternalStore subscriptions.
- Cache sidebar thread DTOs on their derived host name and display title,
  not on the identity of the resources objects.
- Reuse unchanged thread-list tree nodes, items and groups across rebuilds.
- Resolve the row selection menu, project names, collapsed ids and the
  split-drag label without subscribing every row to the whole sidebar.
- Read title-mention resources only for titles that can contain mentions.
- Keep DnD item id arrays and sectionDnd stable while their contents are
  unchanged; while idle, a reorder keeps the sortable order until a drag
  starts (the pinned order, which drives rendering, always updates).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The DnD item-id sharing kept a module-level Map keyed by container id, and
section-group reuse a module-level Map keyed by section key. Both were
written during render and shared by every mounted list. The item ids now
live in the hook's own state; section groups are keyed by their first item
in a WeakMap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/fix-ask-user-question-typing-lag-with-many-threa-thr_fhvv59u7d7 branch from 0cbd3b2 to e788be7 Compare November 16, 2026 21:36
@ymichael
ymichael merged commit d9006ee into main Nov 16, 2026
53 checks passed
@ymichael
ymichael deleted the bb/fix-ask-user-question-typing-lag-with-many-threa-thr_fhvv59u7d7 branch November 16, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant