Skip to content

Keep a reader's line still across restores: aim each from the last aim, not where rounding left the box - #2877

Merged
max-sixty merged 3 commits into
mainfrom
agent-a6c1a859b68f099ee
Oct 14, 2026
Merged

max-sixty merged 3 commits into
mainfrom
agent-a6c1a859b68f099ee

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A reader who doesn't scroll now stays within one pixel of their line across any number of revisions, and a card stays on its pixel while a Threads-list fold corrects for it frame after frame. Before this, each correction added its rounding to the last one's, so what the reader looked at crept across the screen. It settles item 65 of the Lit follow-up review, "WebKit place restores land about 5px off".

Cause

A scroll offset is a whole pixel. Chromium rounds a fractional scrollBy/scrollTo to the nearest pixel and WebKit rounds it down. I measured both for a box and for the page, at device pixel ratios 1 and 2. Words stand at fractions of a pixel, so a restore lands up to a pixel off its aim. A place captured afterwards took that error as part of the reader's place, and the next restore added its own on top.

  • The reported 5px. At Count a scroll as the reader's when it ends, and keep lf-trace's tree places in continuity #2560's commit I logged each frame of the split drag. WebKit's landmark crept down by about half a pixel to a pixel per frame, from 101.75px to 105.875px, because each frame's restore re-recorded the place it had just left and WebKit always rounds the same way. Chromium's errors went both ways and stayed under a pixel. Keep each scroller's reading place across width changes, moved only by the user #2562 stopped this for layout shifts: its holds keep the reader's own reading and don't re-record a box the runtime restored. On main the drag lands 0.75px off in WebKit.
  • What Keep each scroller's reading place across width changes, moved only by the user #2562 left: revisions. Revision continuity (captureView) reads a fresh place at every revision, from wherever the last restore left the box. On a page whose paragraphs stand 36.28px apart, both engines scroll 36px for each paragraph added above, and the reader's line drifts 0.28px per revision.
  • The same in placeKeeper. correct() set scrollTop += delta and then took its new baseline in content coordinates, so it never recovered what the rounding lost. A fold above the reader corrects once per frame. When I stepped a Threads-list fold through 30 frames, the card below drifted 2px in Chromium and 10px in WebKit.

Change

moveScrollerBy (scrolling.js) remembers the fractional offset it aimed at for as long as the box stays at the offset the move left it (aimedTop). capturePlace measures from that aim. The aim isn't kept when the move was smooth, or when the box landed a pixel or more off, since a box clamped at its range doesn't stand at its aim. Every restore that moves through moveScrollerBy gets this, as does every place capture: revisions, region shifts, and the subjects and tabs a region shows. placeKeeper.correct() now moves through moveScrollerBy and aims from where its last correction aimed.

Tests

  • test_revision_after_revision_keeps_the_reader_on_the_same_line (new, Chromium and WebKit): six revisions each add a paragraph above the reader. On main it fails in both engines (259.66px → 261.34px). With the fix it lands at −0.31px in Chromium and +0.69px in WebKit.
  • test_a_fold_frame_by_frame_keeps_the_card_below_on_its_pixel (new, Chromium and WebKit): a held fold steps through 30 frames above the card the reader looks at. On main the card drifts 2px in Chromium and 10px in WebKit. With the fix it doesn't move.
  • test_a_split_drag_keeps_a_panes_reading: the tolerance goes from 8px to 1px, the most one rounding can leave.

Line deltas (item 65)

  • Hand-written source: +36 / −5 (scrolling.js, reading-place.js, user-place.js).
  • Tests: +89 / −3.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 3 commits October 14, 2026 11:21
…the box

A scroll offset is a whole pixel: Chromium rounds a fractional one to the
nearest, WebKit rounds it down (measured for scrollBy and scrollTo, in a
box and the page, at device pixel ratios 1 and 2). Words stand at
fractions of a pixel, so each restore lands up to a pixel short of its
aim. A place captured afterwards read that shortfall as the reader's
place, so the next restore added its own: under repeated revisions the
reader's line crept down the screen, 0.28px per revision in both engines
on a page whose paragraphs stand 36.28px apart.

The same compounding was the "about 5px" WebKit offset in the split-drag
test (#2560): before #2562 each frame's restore re-recorded the place it
had just left, and WebKit's rounding always went one way (101.1px aimed,
105.9px landed). #2562's holds stopped that for shifts; revisions, which
capture afresh, still compounded.

moveScrollerBy now remembers its aim while the box stands where the move
left it (`aimedTop`), and capturePlace reads from that aim. Behavior
change: a reader who doesn't scroll stays within one rounding of their
line across any number of revisions. The split-drag test's tolerance
goes from 8px to 1px.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…creep

placeKeeper corrected with `scrollTop += delta` and then took its new
baseline in content coordinates, so it never recovered the fraction the
engine's rounding lost. A fold above the reader corrects every frame:
stepped through 30 frames, a Threads-list fold left the card below 2px
off in Chromium and 10px off in WebKit. correct() now moves through
moveScrollerBy from `aimedTop`, so each frame aims from the last frame's
aim; the card stays on its pixel. The move is now explicitly instant,
where the assignment followed any `scroll-behavior: smooth` on the box.

The comments say "off its aim" rather than "short": Chromium rounds to
the nearest pixel and can land past it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 00f3715 into main Oct 14, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-a6c1a859b68f099ee branch October 14, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants