Repository navigation
fix(app): keep the reading position when older timeline rows load - #5879
Merged
ymichael merged 1 commit intoOct 20, 2026
Merged
Conversation
Scrolled-up timelines now keep the reading position with one owner, the ScrollPositionKeeper. It anchors a row by its offset in the content and folds layout changes above that row into relative scrollTop writes. Neither the fetch-time prepend capture nor TanStack's cached-offset corrections write the scroll position any more while the reader is detached, so fling momentum and windowing activation can no longer undo the reader's position. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/repro-and-investigate-android-timeline-jump-thr_rtd7gdb7qi
branch
October 20, 2026 18:24
ymichael
added a commit
that referenced
this pull request
Oct 21, 2026
The timeline list sits in an AutoHeightContainer whose explicit height follows its content one ResizeObserver tick late. TimelineWindowedItems snapped it before TanStack's scroll writes, but since #5879 the ScrollPositionKeeper makes those writes and never snapped it. When an older page prepended rows, the keeper's correction was clamped to the old maximum: the reader lost their place and landed on the old bottom. The next scroll event then read that position as a return to the bottom, reattached, and the shell scrolled to the real bottom. The keeper now runs registered scroll extent syncs before any write past the current extent, and TimelineWindowedItems registers the auto-height snap. iOS hold timing is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Oct 22, 2026
Window timeline lists on iOS WebKit too. ScrollPositionKeeper (#5879) stays the only scroll writer, and it gains a hold mode for iOS. While a finger is down, momentum is running, or the edge is bouncing, it keeps the correction as a transform on the scroll content. It writes the correction to scrollTop once scrolling has been still for 150 ms. TanStack reads scrollTop plus the held offset, so the window matches what is on screen. Also: - Upgrade @tanstack/react-virtual to 3.14.20 (virtual-core 3.19.5) and drop the virtual-core 3.17.1 patch, which is fixed upstream. - Restore the saved reading row when a detached reader's scrollport changes width (iPad rotation), clamped to the row's new height. - Re-read the live scroll extent before treating a position past the cached extent as a return to the bottom. - While a saved-row restore waits for its row, park at the bottom instead of the scroll root's initial position. That position could keep loading older pages, all the way to the start of the thread. - Document browser scroll ownership in docs/timeline-pagination.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Oct 22, 2026
The timeline list sits in an AutoHeightContainer whose explicit height follows its content one ResizeObserver tick late. TimelineWindowedItems snapped it before TanStack's scroll writes, but since #5879 the ScrollPositionKeeper makes those writes and never snapped it. When an older page prepended rows, the keeper's correction was clamped to the old maximum: the reader lost their place and landed on the old bottom. The next scroll event then read that position as a return to the bottom, reattached, and the shell scrolled to the real bottom. The keeper now runs registered scroll extent syncs before any write past the current extent, and TimelineWindowedItems registers the auto-height snap. iOS hold timing is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
When you scroll up a long thread, older pages load and get inserted above the reader. Two scroll writers then disagreed about where the reader was:
useAutoLoadOlderRowsaskedBottomAnchoredScrollBodyto recordscrollTopwhen the request started, 600px before the top. After the page arrived, it restoredrecorded scrollTop + inserted height. Fix timeline scroll anchor while older rows load #2427 advanced that record only on scroll events that follow wheel, touch, or key input, so fling momentum after the finger lifts was never counted. The content jumped by however far the fling coasted after the request started, up to ~600px on Android.scrollTop, and ~12 ms later TanStack'sapplyScrollAdjustmentapplied a measurement correction to its cached offset from before the write. That wiped out the restore and sent the reader thousands of px back toward the start of the newly loaded history (e.g.4742 → 865).Both come from several writers (fetch-time prepend restore, TanStack size corrections, native
overflow-anchor) each computing an absolute position from their own stale model.What changed
ScrollPositionKeeper(apps/app/src/components/ui/scroll-position-keeper.ts) is the single owner of the reading position while the reader is scrolled away from the bottom. It anchors the first row that starts in the viewport (descending into nested rows of a row that straddles the top) by its offset in the content, not byscrollTop. Your own scrolling, including momentum, and navigation writes never change that offset; only layout changes above the anchor do. It folds those into relativescrollTop += Δwrites computed from live layout. The anchor is never captured ahead of time, so it cannot go stale.ResizeObservers, everyTimelineWindowedItemscommit, and TanStackonChange(after it repositions rows).TimelineWindowedItems: while the keeper is active, TanStack no longer adjusts or writes scroll (shouldAdjustScrollPositionOnItemSizeChange→ false,scrollToFnskipselementScroll). It registers a row-offset source so the keeper can locate an anchor row the window has not mounted yet (the windowing-activation commit), and the keeper feeds TanStack its writes throughobserveElementOffsetso the range is recomputed before paint. Stuck-to-bottom behaviour is unchanged.BottomAnchoredScrollBody: removescaptureScrollAnchor, the scrollHeight-delta prepend restore, and the input-gated anchor bookkeeping.holdContentPositionnow holds the element edge through the keeper (covering async resizes during the hold) instead of toggling native anchoring and nudgingscrollTop. Nativeoverflow-anchoris off only while the keeper holds a row, and comes back at the bottom.TimelineDetailScroll/useStickyBottomScroll: nested detail scrollers use the same keeper when detached.No wire, CLI, or plugin API changes.
BottomAnchorContextValueis app-internal.How you verified
adbtouch flings against a real 1,954-event thread, with a per-frame row-position probe over CDP:−606,−446,−574 px). When windowing activated, the reading row unmounted (teleport). Also a1691 pxjump at an idle page load.0, 0, 0, 1, 2, 3 px. Mid-fling loads keep the fling velocity continuous.0 px, plus one load that coincided with a 120 px wheel tick).0–11 pxof fling motion on both, and WebKit shows one transient frame at the write on both builds.scroll-position-keeper.test.ts(prepend, momentum before arrival, composition with scrolling, foreign writes, unmounted anchor via a row-offset source, nested anchors, inactive mode, edge holds). New body testkeeps the reading row still when older rows load after momentum scrollingfails on main (no compensation without the fetch-time capture) and passes here. Existing scroll-preservation tests moved to geometry where rows move withscrollTop.pnpm exec turbo run typecheck lint test --filter='...[origin/main]': 16/16 tasks pass.🤖 Generated with Claude Code