Skip to content

Re-render only the rows a renamed sender thread owns - #7606

Merged
ymichael merged 2 commits into
mainfrom
bb/sender-metadata-selector-thr_edin4mcbec
Nov 16, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/sender-metadata-selector-thr_edin4mcbec

Conversation

@ymichael

@ymichael ymichael commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

ThreadTimelineRowsForTimelineView put the whole sender-thread metadata map (useSenderThreadMetadataById()) in SenderThreadMetadataContext, and every ConversationRowContent read 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 per QueryClient. 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 new useSenderThreadMetadata(threadId) returns one thread's entry and re-renders only when that entry changes.
  • ThreadTimelineRows.tsx: SenderThreadMetadataContext is removed. ConversationRowContent and SentThreadMessageRow select 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 ran bb thread update <id> --title …. Two runs each, identical:

Rename ConversationRowContent renders, main this PR Total renders, main this PR
Thread not in the conversation 22 0 516 480
Sender of 3 rows 22 3 (that sender's rows) 593 564

The "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
  • Timeline rows, TOC, prompt-box banner and sender-metadata tests: 28 files, 291 tests passed.

AGENT GENERATED

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]>
ymichael and others added 2 commits November 16, 2026 14:41
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
ymichael force-pushed the bb/sender-metadata-selector-thr_edin4mcbec branch from 81a512f to 5d3e604 Compare November 16, 2026 22:43
@ymichael
ymichael merged commit 4877f9a into main Nov 16, 2026
33 checks passed
@ymichael
ymichael deleted the bb/sender-metadata-selector-thr_edin4mcbec branch November 16, 2026 22:49
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