Repository navigation
Re-render only the rows a renamed sender thread owns - #7606
Merged
Merged
Conversation
ymichael
added a commit
that referenced
this pull request
Nov 16, 2026
## Human comments ## What was wrong `usePluginSlots()` subscribed to the whole plugin slot snapshot, and 57 consumers called it, including per-row ones (`ThreadRowMetadata`, the thread action registry used by every thread row and menu) and `ThreadDetailViewInternal`. Any plugin registration, removal or re-registration (enable, disable, reload, hot reload) re-rendered all of them, even when the change touched an unrelated slot kind. Found in the client perf audit (thr_qgyt9gkt9f). ## What changed - `lib/plugin-slots.ts`: adds `usePluginSlotKind(kind)` and exports `PluginSlotKind`. `buildSnapshot` already keeps each kind's array identity when another kind changes, so a consumer of one kind now re-renders only when that kind changes. - Every consumer moves to `usePluginSlotKind` for the kinds it reads, including the hand-written per-kind `useSyncExternalStore` calls in `ThreadTimelineRows` (four), `composer-slot-hooks.ts` and `PluginTimelineRendererBody.tsx`, which now use the hook. The plugin capabilities page keeps `usePluginSlots()`, because it lists every kind for one plugin. - Two tests that mocked `@/lib/plugin-slots` mock `usePluginSlotKind` instead. - `src/test/render-recorder.ts`: a test helper that records renders through a React DevTools hook (identical to the copy in #7599, #7602 and #7606). ## How you verified Profiling build of the app (react-dom/profiling, compiler on) behind `pnpm start:worktree`, with a thread view open. Test: `bb plugin disable bb--github-star`, then `bb plugin enable bb--github-star`. Two runs each: | | main | this PR | |---|---|---| | Commits | 15 / 15 | 13 / 13 | | Total renders | 3,511 / 3,511 | 2,613 / 2,613 | | React `actualDuration` | 15.6 / 17.0 ms | 12.2 / 12.2 ms | | `ThreadDetailViewInternal` renders | 6 / 6 | 4 / 4 | Test added: `lib/plugin-slots.render.test.tsx`. Registering a plugin that contributes only a settings section re-renders no `ThreadRowMetadata` row. Registering row metadata re-renders each row. The test fails when `ThreadRowMetadata` uses the whole snapshot again. Commands: - `pnpm exec turbo run typecheck lint --filter=@bb/app` - After the follow-up commit: composer, timeline-renderer and plugin-slot render tests (10 files, 106 tests). - App tests under `src/components`, `src/lib`, `src/views` and `src/hooks`: 661 files, 6,983 tests passed. > AGENT GENERATED --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Every mounted conversation row read the whole sender-thread metadata map from a context, so renaming any thread re-rendered every row. The metadata now lives in one ref-counted store per QueryClient that keeps unchanged entries' identity; rows select their own sender with useSenderThreadMetadata(threadId), and the table of contents and queued list share the store instead of rebuilding the map each. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The store rebuilt the whole map on every read until something subscribed, so opening a thread rebuilt it about twice per mounted row. It now watches the query cache for the QueryClient's lifetime, marks the map stale on thread data changes, and rebuilds it on the next read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
force-pushed
the
bb/sender-metadata-selector-thr_edin4mcbec
branch
from
November 16, 2026 22:43
81a512f to
5d3e604
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
ThreadTimelineRowsForTimelineViewput the whole sender-thread metadata map (useSenderThreadMetadataById()) inSenderThreadMetadataContext, and everyConversationRowContentread it. Renaming any thread rebuilt the map, so every mounted conversation row re-rendered, even rows with no sender thread. The table of contents and the queued-message list each rebuilt their own copy of the map from the query cache. Found in the client perf audit (thr_qgyt9gkt9f).What changed
hooks/useSenderThreadMetadataById.ts: the metadata lives in one store perQueryClient. The store watches the query cache for the client's lifetime, marks the map stale when sidebar, thread-list or thread data changes, and rebuilds it on the next read or the scheduled notify. Unchanged entries keep their identity, and so does the map when nothing changed.useSenderThreadMetadataById()reads the map. The newuseSenderThreadMetadata(threadId)returns one thread's entry and re-renders only when that entry changes.ThreadTimelineRows.tsx:SenderThreadMetadataContextis removed.ConversationRowContentandSentThreadMessageRowselect their own sender or recipient.How you verified
Live, on
pnpm start:worktree(production bundle) with a React DevTools hook counting committed renders. Fixture: a thread with 22 conversation rows, 6 sent by two other threads, plus "Sent to" rows. Each rename ranbb thread update <id> --title …. Two runs each, identical:ConversationRowContentrenders, mainThe "Message from" and "Sent to" chips show the new title after a sender rename.
Mount cost: with 40 sender rows, opening the timeline builds the metadata map once. A first version of this change rebuilt it on every read until something subscribed, about twice per row (82 builds).
Test added:
ThreadTimelineRows.sender-metadata.test.tsx. Renaming an unrelated thread re-renders no conversation row. Renaming a sender re-renders only that sender's row, and the new title shows. The test fails on main, where all three rows re-render on the unrelated rename.Commands:
pnpm exec turbo run typecheck lint --filter=@bb/app