Repository navigation
Close the mobile sidebar in the commit that shows the destination - #5870
Merged
ymichael merged 1 commit intoOct 20, 2026
Merged
Conversation
…nation Tapping a sidebar destination on a phone slid the drawer closed at once, while react-router rendered the destination as a transition. The 220 ms settle then forced a sync update that interrupted that render, so the drawer revealed the old page before the new one appeared. - The mobile drawer close is now a transition, so it commits in the same frame as the navigation it accompanies, and the slide starts in a layout effect of that commit. Back/forward close on the popstate that lands the traversal. - The compact new-thread page renders one screenful of recent threads in the navigation commit and the rest in a deferred render. - useComposer() keeps its useSyncExternalStore snapshots pure and gates re-renders in the subscription instead. Reading composer.text during render no longer changes the snapshot, which forced React to throw away and synchronously redo every concurrent render that mounted the plugin. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
force-pushed
the
bb/fix-mobile-thread-navigation-jank-thr_5dnbsnp9bq
branch
from
October 20, 2026 17:16
dc33848 to
0a1fcb3
Compare
ymichael
deleted the
bb/fix-mobile-thread-navigation-jank-thr_5dnbsnp9bq
branch
October 20, 2026 18:33
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
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:useComposer()built itsuseSyncExternalStoresnapshot from a ref that the plugin flips while it renders (by readingcomposer.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:closeMobileSidebarsets the closing state insidestartTransition, 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/goForwardtake an optional callback that fires on thepopstatethat 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 Keep composer plugin consumers off the typing render path #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:
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 readscomposer.textinside a transition renders the rest of the page once (main renders it twice).HistoryCommandHandlers.test.tsxnow runs onBrowserRouter, so back/forward close the drawer on the realpopstate.pnpm exec turbo run typecheck lint test --filter=@bb/apppasses: 6,113 tests, with no new lint findings.🤖 Generated with Claude Code