Repository navigation
Keep composer plugin consumers off the typing render path - #4655
Merged
Merged
Conversation
Split the prompt draft hook into a stable controller and opt-in snapshot hooks so composers, plugin hosts and the new-thread surface no longer re-render on every keystroke. Only the prompt box itself follows the live draft. Plugin composer slots read the draft through a separate context from the static scope/layout/run view, and `useComposer()` subscribes to draft or selection changes only after the calling component reads `text`, `draft`, `isEmpty`, `attachmentCount` or `selection`. Published hook return values are unchanged. The thread list reads draft presence per collapsed row from one published draft-id set instead of threading it through every group builder, so typing in one thread does not rebuild the sidebar tree. Co-authored-by: hemaaanth <[email protected]> Co-Authored-By: Claude Code <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
ymichael
added a commit
that referenced
this pull request
Oct 20, 2026
) ## Human comments ## What was wrong On a phone, tapping a sidebar destination (New thread, a thread row, a plugin panel, back/forward) started the drawer's 220 ms slide immediately, while react-router rendered the destination as a transition. The slide revealed the old page first. When the slide settled, the drawer ran `flushSync(setOpenMobile(false))`, a sync update that interrupted the still-pending navigation render, so the new page appeared only after the drawer was already gone. The navigation render itself was also slower than it needed to be: - The compact new-thread page mounted every recent thread at once (79 rows, about 1,430 elements, in a list 4,818 px tall, with about 4 rows visible). - `useComposer()` built its `useSyncExternalStore` snapshot from a ref that the plugin flips while it renders (by reading `composer.text`). React's end-of-render tearing check therefore saw a changed snapshot, threw the concurrent render away, and redid the whole tree synchronously. ## What changed - `components/ui/sidebar.tsx`: `closeMobileSidebar` sets the closing state inside `startTransition`, so it shares the lane of a navigation started in the same event and commits with it. The slide starts in a layout effect of that commit. Closes that are not part of a navigation (backdrop, Escape, trigger) commit on the next frame. - `lib/app-route-history.ts`, `HistoryCommandHandlers.tsx`, `SidebarHistoryNavigationControls.tsx`: `goBack`/`goForward` take an optional callback that fires on the `popstate` that lands the traversal. The drawer closes there, in the same commit as the route. - `views/RootComposeMobileRecents.tsx`: renders one screenful of rows in the navigation commit and the rest in a deferred render (`useDeferredValue(true, false)`, which defers the first mount only). - `lib/plugin-sdk-hooks.ts`: `useComposer()` snapshots read the draft and selection directly. The "only re-render plugins that read the text" behaviour from #4655 moved into the subscription callbacks. ## How you verified Real data from the local bb, a 390×844 phone viewport, tapping New thread from the open drawer on a 7,900-event thread: | | main | this PR | | --- | --- | --- | | iOS Simulator Safari (iPhone 16 Pro, iOS 18.4, 5 runs): new page committed | 126–184 ms (median 132) | 67–73 ms | | iOS Simulator Safari: new page first painted | 201–306 ms (median 260), after the drawer has already revealed the old page | 138–143 ms, revealed by the slide | | Headless Chrome 1× (4 runs): committed | 87–100 ms | 53–66 ms | | Headless Chrome 2× CPU slowdown (4 runs): committed | 162–174 ms | 90–92 ms | On main, the slide starts at 1–11 ms. With this PR it starts in the commit that shows the new page. A CPU profile of the branch shows no tearing re-render, and the forced layout on the new-thread page dropped from about 26 ms to about 5 ms at 1×. Tests, each of which fails on main and passes here: - `sidebar.test.tsx`: while a navigation is still suspended, the drawer must not start sliding. It slides in the commit that shows the destination. - `plugin-slot-mounts.test.tsx`: mounting a plugin that reads `composer.text` inside a transition renders the rest of the page once (main renders it twice). - `HistoryCommandHandlers.test.tsx` now runs on `BrowserRouter`, so back/forward close the drawer on the real `popstate`. `pnpm exec turbo run typecheck lint test --filter=@bb/app` passes: 6,113 tests, with no new lint findings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) > AGENT GENERATED Co-authored-by: Claude Opus 5.5 <[email protected]>
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
usePromptDraftStoragereturned the live draft, so every component that needed any draft operation re-rendered on each keystroke: the composers, the plugin composer host with its banners and actions, and, through draft-presence ids threaded into the group builders, the sidebar tree.useComposer()subscribed every plugin composer contribution to draft and selection changes whether or not it read them.What changed
Split out of #4532 (commits 087cbc3 and aab5c06 together, applied on current main). Part 6 of 6. Independent of the suggestion warm-up PR; the two merge cleanly.
apps/app/src/hooks/usePromptDraftStorage.ts: a stableusePromptDraftControllerplus opt-inusePromptDraftSnapshotandusePromptDraftInputEmpty. Debounce, flush onpagehide/visibilitychange, the cross-tabstoragelistener,clearIfCurrentMatchesandrestoreIfEmptyare unchanged.apps/app/src/components/plugin/plugin-composer-host.tsx,PluginComposerBanners.tsx,PluginComposerActions.tsx,promptbox/PromptBoxActionsMenu.tsx: static scope/layout/run view split from the draft context; banner rows and the action list are memoized.apps/app/src/lib/plugin-sdk-hooks.ts:useComposer()subscribes to the draft only once the caller readstext,draft,isEmptyorattachmentCount, and to selection only once it readsselection. Returned values are unchanged and no public SDK member is added.apps/app/src/components/promptbox/NewThreadComposer.tsx: onlyLiveDraftNewThreadPromptBoxfollows the live draft.plugins/thread-list: collapsed rows read draft presence from one published draft-id set (list/sidebarDraftPresence.ts) instead of adraftThreadIdsargument through every group builder.Not included from #4532: the re-added
addQuote(removed on main in #4474 and unused), theThreadDetailPromptAreamemo (needs stable props from another commit), and the scheduled-send formatter caching.Review note: lazy tracking writes two refs during the plugin's render, which adds one
react(refs)lint warning atplugin-sdk-hooks.ts. A draft change between the render that first reads a field and its commit is seen on the following change.How you verified
pnpm exec turbo run typecheck lint --filter=@bb/app --filter=bb-plugin-thread-list: pass, 0 lint errors (app warnings 208 vs 207 on main, the one above).pnpm exec turbo run test --filter=@bb/app --filter=bb-plugin-thread-list --concurrency=1:@bb/app5,185 passed, 6 skipped; thread-list 443/443.plugin-slot-mounts.test.tsx: a plugin that starts readingtext/isEmptyonly after a local toggle keeps updating, and a plugin that reads onlyuseComposer().selectionre-renders on picker changes. Both fail with tracking disabled (the state of 087cbc3 alone).🤖 Generated with Claude Code