You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
app: ScrollPositionKeeper.handleScroll() runs apply(), capture(), and notifyLists() twice per detached scroll event #8496
In apps/app/src/components/ui/scroll-position-keeper.ts, the detached (position.kind !== "bottom") branch of handleScroll() performs duplicate layout reads, writes, anchor captures, and list notifications on every single scroll event (60–120 Hz while scrolled up in a thread):
Line 532: this.apply(scrollElement, false) reads scroll geometry and may write scrollTop / style.transform.
Line 534–535: this.isInView(...) forces a layout read (getBoundingClientRect()), and this.capture(scrollElement) runs querySelectorAll + binary-search getBoundingClientRect() + up to 8 neighbor getBoundingClientRect() reads.
Line 537: this.notifyLists() invokes TimelineWindowedItems.syncWindow(true).
Line 538: 2ndthis.apply(scrollElement, false) repeats the geometry read/write pass.
Line 539: Unconditional 2ndthis.capture(scrollElement) repeats querySelectorAll + binary-search getBoundingClientRect() and unconditionally overwrites the anchor captured on line 535.
Line 542–543: this.attachIfAtEnd(scrollElement) followed by a 2ndthis.notifyLists().
Environment
Commit: bdd066bc5076b5bdcc6d37ecec52c17ad59e9493
Chromium headless (1440×900, Linux x64)
Measured Impact (Headless Chromium)
Benchmarking 120 detached scroll events over a 300-row timeline (~15 DOM nodes/row) in headless Chromium comparing the current double apply/capture/notifyLists sequence against a single pass:
On heavier real threads with code blocks, diffs, and nested tool cards, forced reflow cost scales linearly with DOM size.
Expected Behavior
Avoid redundant apply(), capture(), and notifyLists() passes inside handleScroll()'s detached branch so each scroll event does at most one capture/reconcile pass unless the first notifyLists() actually mutated the DOM/window, while preserving all invariants covered by scroll-position-keeper.test.ts and scroll-position-keeper.model.test.ts.
Adding a minimal runnable Vitest repro against ScrollPositionKeeper on f5af70c9c5 (same harness as apps/app/src/components/ui/scroll-position-keeper.test.ts):
Activity
Tiberriver256 commentedon Dec 2, 2026
Adding a minimal runnable Vitest repro against
ScrollPositionKeeperonf5af70c9c5(same harness asapps/app/src/components/ui/scroll-position-keeper.test.ts):Observed output (
npx vitest run --silent=false):Every detached scroll event fires
onPositionChange(notifyLists) 2× (and callscapture()/getTopLevelRows2× whenever the previous anchor scrolls out of view).