Repository navigation
fix: don't fight browser scroll anchoring (#222) - #261
justin-schroeder wants to merge 3 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Parking as draft
The tests here only cover fully-offscreen insert/remove. Next step is a sounder way to tell anchoring apart from clamps/pending scrolls (e.g. measuring a visible reference element's viewport position across the mutation), with all of the above as regression tests. Not shipping in 0.11.0. |
|
Second, deeper attempt: no fully correct heuristic found. When a scroll and a mutation land in the same task, neither the scroll-event position nor geometry reliably separates user/programmatic scrolling from browser anchoring. I added draft regression specs to this branch. Notably, master already fails several of these (pending scroll + insert, partially visible insert, nested-container removal, already-scrolled init, smooth pages) in Chromium/Firefox, so this is long-standing, not new. Keeping this as a draft research branch; the user-facing workaround ( |
Fixes #222.
Root cause (found in the reporter's video): when an item is added or removed above the viewport, Chrome and Firefox scroll-anchor the page so visible content keeps its on-screen spot. Safari has no scroll anchoring, which is why it looked fine there. AutoAnimate compares page coordinates, so it saw visible items "move" by one row and animated them back, making them jump and slide. For removals,
adjustScrollalso undid the browser's anchoring, and re-inserting the leaving element made Chromium re-scroll.Fix
remain: the browser's own scroll since the last scroll event (scroll events fire a frame later, so this is the anchoring shift, not user scrolling) is folded into the old coordinates. Items that kept their screen position don't animate. Page-scrolled content only; nested scrollers are unchanged.removeof an element that was entirely above the viewport: skipadjustScroll(it's for removals that shorten the page), keep the leaving element out of anchor selection (overflow-anchor: none), and return to the browser's anchored scroll position after the element is re-inserted.Tests: new
scroll-anchoring.spec.ts(insert and remove above the viewport) samples a visible item's on-screen position every frame. Before the fix it fails on Chromium and Firefox and passes on WebKit, exactly matching the report. After the fix it passes in all three, 2 repeats each. The full e2e suite: 133 passed, 8 skipped.