Skip to content

Fix timeline drift when thread context banner loads - #5067

Merged
ymichael merged 1 commit into
mainfrom
bb/investigate-thread-prompt-shift-thr_cwx3jvngau
Oct 6, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/investigate-thread-prompt-shift-thr_cwx3jvngau

Conversation

@ymichael

@ymichael ymichael commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

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

  • Regression cases failed before the fix and pass afterward: compensation for 24px, 35px, and 64px stacks, synchronous updates, duplicate-measurement avoidance, and plugin banner compensation.
  • 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.
  • Built and ran 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).

AGENT GENERATED

@ymichael
ymichael merged commit 03b3803 into main Oct 6, 2026
41 checks passed
@ymichael
ymichael deleted the bb/investigate-thread-prompt-shift-thr_cwx3jvngau branch October 6, 2026 22:13
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant