Repository navigation
Fix timeline drift when thread context banner loads - #5067
Merged
Merged
Conversation
5 tasks
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
When Git context loaded, the collapsed banner added 35px but the follow-up input could compensate for only 32px. The extra 3px increased the footer height and shifted bottom-anchored timeline messages. Stack compensation also waited for an asynchronous resize update, allowing the composer to show an intermediate layout.
What changed
Share the collapsed context banner's 35px height with the composer's elastic height budget. Measure stack replacements in a layout effect and synchronously commit ResizeObserver compensation, retaining the input's minimum height and skipping unchanged measurements. The banner continues to remain absent while loading.
How you verified
pnpm exec turbo run test --filter=@bb/app -- src/components/promptbox/FollowUpPromptBox.test.tsx src/components/promptbox/banner/ThreadPromptContextBanner.test.tsx src/views/thread-detail/ThreadDetailPromptArea.test.tsx— 126 tests passed.pnpm exec turbo run lint typecheck --filter=@bb/app— passed; lint reported warnings and no errors.pnpm start:worktree. In Chromium with populated synthetic timelines and Git responses delayed by 1.2 seconds, verified direct loads, sidebar switching, and a cached banner disappearing after the workspace became clean. Across banner appearance and disappearance, the visible message position, scroll offset, and total composer height remained unchanged (0px timeline movement).