Repository navigation
Subscribe plugin slot consumers to the slot kinds they read - #7609
Merged
Merged
Conversation
usePluginSlots() returned the whole slot snapshot, so registering any plugin contribution re-rendered every consumer, including per-row ones such as ThreadRowMetadata and the thread action registry. usePluginSlotKind(kind) subscribes to one kind; the snapshot already keeps each kind's array identity when another kind changes. Every consumer moves to it except the plugin capabilities page, which lists every kind. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/plugin-slot-kind-subscriptions-thr_edin4mcbec
branch
November 16, 2026 19:32
ymichael
added a commit
that referenced
this pull request
Nov 17, 2026
#7602) ## Human comments ## What was wrong `ComposerBox` received the draft as `value`, `mentionRanges` and `onChange` props. The thread composer's owner, `ThreadDetailPromptArea`, subscribed to the whole prompt draft to provide those props. As a result, every keystroke re-rendered the prompt area, every banner (context, todos, workflows, machine status), the execution controls, `FollowUpPromptBox` and `ComposerBox`. `ComposerBox` also rebuilt `registerEditor` on every render, so `ComposerRoot` re-registered the editor from a layout effect. That republished the editor bridge and caused a second synchronous commit of the composer subtree (`ComposerRoot`, `ComposerPluginActions`, `VoiceInputButton`, `MicrophonePreferencesPopoverContent`, plugin slots). Found in the client perf audit (thr_qgyt9gkt9f). ## What changed - `plugin-composer-host.tsx`: adds `ComposerDraftStore`, which has `PluginComposerHost`'s `getCurrent`/`subscribeDraft`/`setDraft` shape, so any host is a store. It also adds `useComposerDraftSelector` (a cached `useSyncExternalStore` selector) and `createComposerDraftStore`. `PluginComposerViewProvider` now takes a static view plus a draft source. `useOptionalPluginComposerView()` derives the draft part through the selector, so only readers of the draft re-render. - `ComposerBox`: takes `draft: ComposerDraftStore` in place of `value`/`mentionRanges`/`onChange`. `AttachmentsConfig.items` and `HistoryConfig.currentDraft` are gone, because the box reads them from the store. - The box subscribes to the store itself. It builds `history.currentDraft`, the retired `view` member and the attachments from the current draft on every keystroke, exactly as before, so the plugin-facing renderer API behaves as it did on main. Only the box re-renders while typing. - `registerEditor` and `attachEditor` keep their identity across keystrokes, so `ComposerRoot` re-registers the editor only when the host, key, layout or editor state changes. The bridge's `submit` reads the latest submission and voice state when called. - `FollowUpPromptBox`, `NewThreadPromptBox`/`NewThreadComposer`, `ComposerExtensionHost` and `usePromptModePermissionDisplay` take the store. Plan-mode detection is a boolean selector, using `planPermissionDisplay`, which is now exported from client-core. - `ThreadDetailPromptArea` / `useActiveComposerDraft`: the main composer passes its prompt-draft host. The queued and sent-message editors pass their own hosts. The prompt area subscribes only to whether the draft has input. - No plugin API or SDK change. The composer plugin is untouched, and composer forks that react to `history` changing keep working. - Render invariants: "typing in the composer renders nothing outside the composer box" from #7601 is on in CI. Its region is the composer box (`[data-composer-box]`) rather than the inner `form`, because the box's own host re-renders once per keystroke to hand plugins the current draft. - Tests and stories: `ControlledComposerBox` (in `src/test/fixtures`) keeps the existing controlled-value editor tests running on the store API. One race test was rewritten to the production path, where the store write and the focus-end key land in one batch. The history navigation harness restores entries through a real draft store, as the thread and new-thread composers do. The new tests record renders with `src/test/render-recorder.ts`, which main already has from #7609. The inline queued-message and sent-message editors still hold their draft in React state, so typing in them still re-renders their owner. Only the main and new-thread composers changed. ## How you verified Production build behind `pnpm start:worktree`, typing 20 characters into a thread composer with a React DevTools-hook recorder counting commits and component renders. Every run gave identical counts: | | main | this PR | |---|---|---| | Commits | 40 (2 per key) | 20 (1 per key) | | Component renders | 5,400 | 2,280 | | Renders outside the composer form | 1,040 | 200 | The 200 renders outside the form are 20 renders of `ComposerRendererHostProvider` (the box's host, once per key) and the composer plugin's own portaled dialog components. Plugin compatibility: with main's composer plugin code, ArrowUp history works as on main. Recalling an entry, editing it, clearing the box and pressing ArrowUp recalls the newest entry. Editing a recalled entry, undoing the edit and pressing ArrowUp leaves the draft in place. Tests (each fails when the regression it names is reintroduced): - `composer-contract.test.tsx`: on every surface (follow-up, embedded chat, queued, sent-message editor, steering, new thread), typing renders nothing outside the composer box, renders the plugin composer once per keystroke, and hands plugins a new `history` whose `currentDraft` is the typed text. The once-per-keystroke check fails (6 renders for 3 keys) when `registerEditor` loses its identity. - `ThreadDetailPromptArea.keystrokes.test.tsx`: once the draft has text, keystrokes render nothing outside the composer input. - `PluginNewThreadComposer.test.tsx`: typing re-renders neither the composer surface nor the prompt box. - `tests/render-invariants`: the composer typing invariant passes in a real browser; the suite passes with it on. Commands: - `pnpm exec turbo run typecheck --filter='...[origin/main]'`: 108 tasks passed. - `pnpm exec turbo run lint --filter=@bb/app`: 0 errors. - Affected app tests (promptbox, plugin, thread-detail, thread composer, RootCompose, plugin slots): 130 files passed. - `bb-plugin-bb--composer` tests passed. - `pnpm exec turbo run test:render-invariants --filter=@bb/render-invariants`: passed. Manual check on the rebuilt dev instance: typing, Enter to send (composer clears, the reply arrives), ArrowUp history recall, editing a recalled entry, the sent-message editor (typing, Escape keeps the bottom draft) and typing in the new-thread composer all work. > AGENT GENERATED --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Nov 17, 2026
Merged
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
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) andThreadDetailViewInternal. 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: addsusePluginSlotKind(kind)and exportsPluginSlotKind.buildSnapshotalready keeps each kind's array identity when another kind changes, so a consumer of one kind now re-renders only when that kind changes.usePluginSlotKindfor the kinds it reads, including the hand-written per-kinduseSyncExternalStorecalls inThreadTimelineRows(four),composer-slot-hooks.tsandPluginTimelineRendererBody.tsx, which now use the hook. The plugin capabilities page keepsusePluginSlots(), because it lists every kind for one plugin.@/lib/plugin-slotsmockusePluginSlotKindinstead.src/test/render-recorder.ts: a test helper that records renders through a React DevTools hook (identical to the copy in Keep timeline pushes from re-rendering the thread view #7599, Give the composer a draft store so keystrokes stay inside the composer #7602 and Re-render only the rows a renamed sender thread owns #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, thenbb plugin enable bb--github-star. Two runs each:actualDurationThreadDetailViewInternalrendersTest added:
lib/plugin-slots.render.test.tsx. Registering a plugin that contributes only a settings section re-renders noThreadRowMetadatarow. Registering row metadata re-renders each row. The test fails whenThreadRowMetadatauses the whole snapshot again.Commands:
pnpm exec turbo run typecheck lint --filter=@bb/appsrc/components,src/lib,src/viewsandsrc/hooks: 661 files, 6,983 tests passed.