[luv-292] fix: keep virtualizer scrollMargin in sync with layout shifts#292
Conversation
The session log viewer's `useWindowVirtualizer` captured `scrollMargin` once via a callback ref on the list wrapper's `offsetTop`. The ref only fires on mount, so any layout change above the list — async hook-activity panel mounting, subagent collapse/expand, window resize — left the value stale. The virtualizer then mapped window scroll → list coords with the wrong offset, positioning each item at the wrong y-offset and exposing the page `--background` (#031035) under the otherwise empty container, giving the "page goes blue while scrolling" symptom. Replace the callback ref with a stable `useRef<HTMLDivElement>` and a `useLayoutEffect` that re-measures via `getBoundingClientRect().top + window.scrollY` from a `ResizeObserver` on `document.body` plus a window resize listener. Functional `setScrollMargin` short-circuits same-value updates so the body resize the update itself causes can't loop. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe Session log viewer's scroll margin calculation is refactored from a mount-only callback ref using ChangesSession Log Viewer Scroll Margin Recalculation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
Summary
--background(#031035) under the empty virtualized container — the "page goes blue while scrolling" symptom.app/components/raw-log-viewer.tsxcaptureduseWindowVirtualizer'sscrollMarginonce in a callback ref readingoffsetTop. The ref fires on mount only, so any layout shift above the list (asyncsearchHookActivityActionresolving and mounting<SessionHooksPanel>, Subagents-section / per-subagent collapse-expand, window resize re-flowing StatsBar / ToolStatsGrid) left the value stale. The virtualizer then mapped window scroll → list-local coords with the wrong offset and translated each item byvirtualRow.start - staleScrollMargin.useRef<HTMLDivElement>+useLayoutEffectthat re-measures viagetBoundingClientRect().top + window.scrollYfrom aResizeObserverondocument.bodyand awindowresize listener. FunctionalsetScrollMargin(prev => prev === top ? prev : top)short-circuits the body-resize feedback the update itself causes.Test plan
bun run lintclean (one pre-existing unrelated warning intool-input-output.tsx)bunx tsc -p tsconfig.json --noEmitcleanbun run test:run— 1452/1452 unit tests passbun run dev, open a session that has hook activity (soSessionHooksPanelmounts async), scroll mid-list, confirm no blue gap and entries fill the viewport#entry-<uuid>hash navigation still scrolls to the correct entry🤖 Generated with Claude Code
Summary by CodeRabbit