Repository navigation
Description
Summary
The git-diff ("code review") secondary-panel tab discards its scroll position whenever you switch to another tab and back, dropping reviewers at the top of a long diff. The fix is small and mirrors a pattern BB already ships for file-preview tabs — a prototype with tests is ready (linked below). Opening this first per CONTRIBUTING, since it touches UI.
Context
In the thread's secondary panel you can flip between the git-diff review tab and other tabs (thread info, file previews, terminals). File-preview tabs remember where you scrolled to when you come back. The git-diff tab does not: returning to a review you were halfway through snaps you back to the first file. On a large changeset this means re-scrolling and re-finding your place every time you glance at another tab.
Steps to reproduce
- Open a thread whose environment has a sizable git diff (enough to scroll).
- Open the secondary panel's git-diff ("code review") tab.
- Scroll partway down the diff.
- Switch to another panel tab (e.g. thread info or a file preview).
- Switch back to the git-diff tab.
Expected: the diff is still scrolled to where you left it (as file-preview tabs already behave).
Actual: the diff is scrolled back to the top.
Root cause
The git-diff tab is a fixed tab: it renders in a different branch from file-preview tabs and unmounts on tab switch, so its virtualized scroll container (DiffFilesPanel) is recreated from scratch.
- File-preview tabs persist scroll via a scoped position map and
FilePreviewScrollPositionContext(apps/app/src/components/secondary-panel/ThreadSecondaryPanel.tsx, ~L115-128, L723-734, L844-852; restore pattern inFilePreview.tsxL1041-1053). - The git-diff fixed-tab branch (
ThreadSecondaryPanel.tsxL854-866) wraps content only inThreadDiffContentContext— there is no scroll-position persistence.
Proposed fix
Persist the git-diff scroll offset the same way the panel already persists per-file collapse state: in diffFilesStore via a jotai atomFamily keyed by diffIdentity. DiffFilesPanel restores the offset on remount in a layout effect (setting scrollTop, matching the file-preview precedent) and saves it on scroll. A pending deep-link scroll target (scrollToPath) still takes precedence, and stale offsets are pruned on diff-identity change alongside the existing card-state cleanup.
Note: initialOffset on the virtualizer is not enough here — for an element-scoped virtualizer observeElementOffset reads the real scrollTop (0) on mount and overwrites it, so a layout-effect restore is used instead.
Touches 3 files (+32/-3) plus a test. Prototype branch: https://github.com/kolsha/bb/tree/feat/git-diff-scroll-persist
Verification
- New behavior test
DiffFilesPanel.scrollPersist.test.tsx(restore across unmount/remount, per-identity isolation, cleanup, deep-link precedence); confirmed it fails without the fix. - git-diff + secondary-panel suites green (58/58), typecheck and oxlint clean.
Ruled out
- A plugin (
experimental_diffRenderer) — it replaces per-file diff bodies, not the panel's scroll container or tab lifecycle, so it cannot address this. - Keeping the tab mounted (display:none) — larger architectural change and against the panel's current unmount-based pattern, which file previews already work around with the scoped position map.
Environment: bb 0.46.1 (reproduces on current main).
Activity
bb-slop-cop commentedon Oct 23, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotui.origin/main.confirmed-repro.kolsha commentedon Oct 23, 2026
Update: pivoted from scroll-restore to an opt-in keep-alive experiment
The original "persist and restore the scroll offset" approach turned out to be the wrong shape for this panel, confirmed by testing:
scrollTopdrifts once off-screen rows re-measure after the switch — the position lands in the wrong place.measurementsCache+initialOffsetreduced but did not eliminate the drift on real diffs.The robust fix is to not tear the panel down. Reworked prototype:
visibility(notdisplay:none, which resetsscrollTop) so scroll position and already-loaded diffs survive the switch.reviewTabKeepAliveexperiment (Settings → Experiments), so default behavior is unchanged and this is pure opt-in.SidebarSplitContainer).Clean prototype (force-pushed, restore approach dropped from history): https://github.com/kolsha/bb/tree/feat/git-diff-scroll-persist — 4 files, +35/-2 (
ThreadSecondaryPanel.tsxkeep-alive layer + the experiment indomain, system-config fallback, and the Experiments settings UI). typecheck/lint clean. Verified working on a local build against a copy of real data.Open question for maintainers: the secondary panel unmounts inactive tabs deliberately (memory/perf with many tabs, browser views, terminals). Is an opt-in keep-alive for just the git-diff tab an acceptable direction, or would you prefer a different mechanism? Happy to adjust before this becomes a PR.