Skip to content

Keep diff panel card heights stable while scrolling - #6494

Merged
ymichael merged 1 commit into
mainfrom
bb/debug-diff-panel-scrolling-thr_ujhq928geq
Oct 28, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/debug-diff-panel-scrolling-thr_ujhq928geq

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Dragging the Diff tab scrollbar jumped between distant files instead of following the mouse. The thumb maps to fraction × total height, and the virtualized list's total height kept changing mid-drag, between about 15k and 90k px on a 42-file diff. Three things fed the virtualizer heights that weren't real:

  • Each card body showed a 168 px loading skeleton until an IntersectionObserver fired. That state reset whenever the virtualizer remounted the card, so a cached 8,158 px measurement was replaced by 168 px and the browser clamped the scroll position. Dragging to 50% landed near the bottom.
  • content-visibility: auto with contain-intrinsic-size: 0 600px sized every off-screen body at 600 px, its real height on screen, and 600 px again once it left the screen.
  • Estimates stopped counting at 80 lines, ignored files that load on demand, and read each card's initial collapsed state. With more than 10 files, every unseen card was still estimated as collapsed after "Expand all".

What changed

  • packages/shared-ui/.../GitDiffCardBody.tsx: removed the renderBeforeVisible IntersectionObserver gate, so bodies render on mount. The list virtualizer already limits what mounts, and the timeline card already passed true. Added a defersOffscreenRendering prop: the unvirtualized timeline card (apps/app/.../GitDiffCard.tsx) keeps content-visibility, and the Diff tab turns it off.
  • plugins/git/ui/diff/diffFilesStore.ts: estimates count every changed line, use the notice height for on_demand/too_large files, and use the measured 33 px header and 17 px body padding. Each write now replaces the per-diff state map so the panel can subscribe to it (useDiffFileCardStates).
  • plugins/git/ui/diff/DiffFilesPanel.tsx: estimates use the current collapsed state, the measurement key includes that state so collapsed and expanded heights are cached separately, and rows receive collapsed from the panel.
  • plugins/git/ui/diff/DiffFileCard.tsx: the skeleton shown while a patch loads reserves the estimated body height.

How you verified

  • Real dev instance with a 42-file fixture: 30 added files of 32–450 lines and 12 modified files. A scripted drag set scrollTop from the thumb fraction against the current scrollHeight, as Chromium does on each mouse move.
    • Before: scrollHeight went 14.8k → 56.9k px on the first drag and kept shifting on the second, as far as 79k → 17k with scroll clamping.
    • After: 85.4k → 89.1k on the first drag and 88.9k → 89.1k afterwards. The file at the top only moves forward, and expand-all goes straight to the right total.
  • Perf, same fixture: no long tasks either way at 1× CPU. Under 4× CPU throttling, total long-task time was 1.9–2.6 s after versus 2.0–4.5 s before. The worst single frame was comparable: 217–350 ms after versus 183–283 ms before.
  • Tests: pnpm exec turbo run typecheck lint --filter=@bb/shared-ui --filter=bb-plugin-bb--git --filter=@bb/app passes. pnpm exec turbo run test passes for shared-ui (75), the git plugin (249), and the app's git-diff and timeline suites (420). The store test that asserted the 80-line cap now checks per-line scaling and the on-demand notice estimate.
  • Manual: pnpm start:worktree with the fixture, checked in the browser.

AGENT GENERATED

🤖 Generated with Claude Code

Dragging the Diff tab scrollbar jumped between distant files because the
virtualizer kept measuring transient card heights. Each remounted card
rendered a 168px skeleton until an IntersectionObserver fired, replacing
its cached real height, and content-visibility sized off-screen bodies at
600px. The total height swung between ~15k and ~90k px mid-drag, so the
thumb mapped to different content on every move.

Render card bodies as soon as they mount (the virtualizer already limits
mounting), keep content-visibility only for the unvirtualized timeline
card, estimate every changed line and the on-demand notice, key
measurements by collapsed state, and reserve the estimated height while
a patch loads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit e08b81d into main Oct 28, 2026
50 checks passed
@ymichael
ymichael deleted the bb/debug-diff-panel-scrolling-thr_ujhq928geq branch October 28, 2026 22:38
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