Repository navigation
Keep the timeline still when a prompt banner appears - #6488
Merged
ymichael merged 1 commit intoOct 28, 2026
Merged
Conversation
The follow-up composer shrinks its editor when the prompt stack grows, so a collapsed banner like the git changes strip should not change the footer height. The shrink ran from the stack's ResizeObserver, after the scroll keeper's observer had already scrolled for the taller footer. The browser skips the keeper's follow-up notification in that pass, so one frame painted the timeline and composer 35px too high before snapping back. Re-measure the keeper right after the stack resize is applied. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/fix-timeline-vertical-shift-on-tab-switch-thr_ecc9zp52eq
branch
October 28, 2026 22:06
2 tasks done
ymichael
added a commit
that referenced
this pull request
Nov 17, 2026
## Human comments ## What was wrong A `ResizeObserver` callback runs after layout and before paint, but React applies a plain `setState` from that callback in a later task, after the browser has painted. Any layout derived from a measured size therefore painted one frame with the old layout at the new size. #7497 (context card), #5067 and #6488 (composer prompt stack) each fixed one instance by hand with `flushSync`. A survey found about 30 more sites with the same pattern: TOC show/hide, header action overflow, message action row count, "Show more" toggles, File Preview header buttons, panel size limits, resource toolbar, overflow fades, and others across `apps/app`, `shared-ui`, plugins and `apps/web`. Measured in headless Chrome, crossing a width threshold 10 times: | How the measured size reaches React | Frames painted with the old layout | |---|---| | plain `setState` in the observer | 10 of 10 | | `flushSync` | 0 | | `useSyncExternalStore` | 0 | ## What changed - **One path for element sizes.** `observeSharedResize` moved from `apps/app/src/lib` to `@bb/shared-ui/lib/shared-resize-observer`, which also makes it a component-registry item for forkable plugins. It keeps the one-`flushSync`-per-batch writes and `settleAfterSharedResizeWrites` that #7612 added, so React state from a resize renders before paint. It now also: - accepts a list of targets and runs each registration once per batch; - returns a no-op where `ResizeObserver` is missing. - **`useMeasuredValue(target, read, initial)`** in `@bb/shared-ui/hooks/use-measured-value` for the simple ref-to-value case. It replaces usehooks-ts `useResizeObserver` in the git plugin. - **Lint guard.** `bb/no-raw-resize-observer` in `scripts/oxlint-plugin.mjs` rejects `new ResizeObserver` and usehooks-ts `useResizeObserver` outside the shared module, apart from tests and stories. Two files are exempt in `.oxlintrc.json` because their own callback batching only writes the DOM and doesn't set React state: - `scroll-position-keeper.ts`: the timeline engine's own observer, which reconciles once per batch. - the landing hero feed animation in `apps/web`. - **Migration.** 58 sites across `apps/app`, `shared-ui`, 13 plugins and `apps/web` now use the shared path. Read steps only read layout; write steps write the DOM and set state. - The `flushSync` workarounds in the sidebar header slot and context card are gone. - The composer prompt stack keeps its inner `flushSync`, because `positionKeeper.remeasure()` must run after the new height commits. - #7612's new call sites (timeline row heights, `useIsOverflowing`, markdown table geometry) import the moved scheduler. - TOC visibility and the background-commands card now measure on first paint instead of waiting for the observer's first callback. - `ThreadDetailHeader` keeps a narrow/wide flag instead of the pane width, so a divider drag no longer re-renders the header every frame. - The component registry is regenerated: a new `shared-resize-observer` item, and expandable-text, question-form, resource-pagination and resource-toolbar now depend on it. No wire, CLI or user-facing configuration changes. ## How you verified - New tests in `packages/shared-ui/src/lib/shared-resize-observer.test.tsx`: - state written by a resize renders before the observer callback returns; - `useMeasuredValue` measures on mount and on each resize; - a registration with several targets runs once per batch. - The first two fail with the `flushSync` batching removed. - The lint rule flags the original code of the past fixes at the exact line each one changed: `PluginThreadContextCard.tsx:371` (#7497), `FollowUpPromptBox.tsx:668` (#5067) and `FollowUpPromptBox.tsx:685` (#6488). - `pnpm exec turbo run typecheck lint --filter='...[origin/main]'`: 180/180 passed. - `pnpm exec turbo run test` on every affected package passed after the fixes below: - Two `@bb/app` tests failed because their `ResizeObserver` stubs called the callback without entries; I fixed the stubs. - These failed under load and passed on a rerun alone: - `bb-plugin-connect` `connect.test.ts` (72/72) - four `@bb/server` files (131/131) - `CommandPalette.test.tsx` - `marketplace-exposure.test.tsx` - `plugin-guide.test.ts` failed because an interrupted bundling run had left a gitignored `plugins/.bundled-stage-*` copy of navigation. Removing it made it pass. - Live, with `pnpm start:worktree`, the experiment on and the context card pinned, I recorded every resize frame while opening and closing the right panel twice at 1440, 1600 and 2560px: - main before #7497: 1 stale frame per band crossing; - this branch: 0 at every width. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- 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
Switching to a thread whose environment has git changes made the timeline jump up about 35px for one frame and then drop back, at the moment the "Committed · N files" bar appeared above the composer. The follow-up composer is meant to absorb a collapsed banner: it shrinks its editor by the prompt stack's measured height, so the footer height stays the same. That shrink runs from the stack's
ResizeObserver, which was created after the scroll keeper's observer and so ran after it. In that pass the keeper first scrolled to the end of the taller footer. The composer then shrank back. The browser does not deliver a resize of an element at or above the shallowest depth it already handled in the same pass, so the keeper never saw the shrink before paint. Its floor element still held the taller scroll height, so one frame painted the timeline and composer 35px too high, with a gap underneath. Hiding a banner did the reverse.What changed
apps/app/src/components/ui/scroll-position-keeper.ts: the keeper's resize handling (sync the floor, then reconcile) is now a publicremeasure(). The keeper's ownResizeObserveruses it.apps/app/src/components/promptbox/FollowUpPromptBox.tsx: after the stack observer applies a new stack height withflushSync, it callspositionKeeper.remeasure(), so the keeper reconciles the final footer height before paint, whichever observer runs first.No wire, CLI or doc changes.
How you verified
PageShellbottom-anchored timeline, the realFollowUpPromptBox, and the git context banner shown or hidden throughflushSync. Each frame I sampled the last row's top and the composer's bounds:pnpm start:worktreeserver and threads.pnpm exec turbo run typecheck lint --filter=@bb/apppasses. TheFollowUpPromptBox,scroll-position-keeperandbottom-anchored-scroll-bodysuites pass (124 tests). No regression test: jsdom does not implement ResizeObserver depth ordering, which is what triggers this.🤖 Generated with Claude Code