Repository navigation
Hold the reading place until widgets finish preparing, and end a landed glide's scroll at its last frame - #6116
Merged
Merged
Conversation
A glide's last frames move the box less than a pixel, so its last write writes nothing and the browser owes no `scroll` or `scrollend`. In Chromium and Firefox every `d`, `m` and landing therefore ended only by the fallback, 80 ms and two rendering updates later. A glide that lands with a write that moved nothing now releases its hold `landed`, which ends the sequence there; any other release still waits for the owed `scrollend` or the spell. Readers of a scroll's end (choice bookkeeping, place recording, margin re-placement, the hint maps) now run as the glide lands. Probe on review-a-plan, `d` from the top, ms from keydown to the end: Chromium 226-239 -> 142-153, Firefox 224-233 -> 142-148. WebKit, whose last frame still moves the box, ends at its `scrollend` as before.
The window that re-applies a held place after a width change closed after one second whatever was pending, so on a slow device a widget whose preparation landed later moved the text being read. A preparation's release is the event that ends that work, so the window now stays open while one is pending; the one-second cap runs only while none is, bounding a page whose drawing never quiets. Probe: a bounded box with no native anchoring, a preparation that grows content above the reader 1.5 s after the width change. Before, the reader's line moved 37 -> 237 px in Chromium and 38 -> 238 in Firefox; now it stays. A 4 s preparation also stays put.
…sreads one Measured on 2026-11-15 in Playwright's Chromium, Firefox and WebKit: every move that lands gets a scrollend, a script write's, a clamp's and an anchoring adjustment's included; an input that moves nothing, a box removed mid-scroll, Chromium's stop of a smooth scroll and Playwright's wheel in Firefox and WebKit get none. The comment named a scroll restoration, which does get one.
The window that re-applies a held place after a width change polled every animation frame and timed its cap from the last frame that saw a widget preparation pending. Two faults followed. Frames paused past the cap closed it in the first frame after, before the layout a preparation had just committed was heard: in Firefox, a 1.2 s pause before the release moved the reader's line 38 -> 238 px, where a 100 ms pause held it. And a preparation that never lands kept the loop running after the reader's input ended the last hold: 84 frames asked in 1.4 s in Chromium, 168 in Firefox. The window now closes at the first quiet rendering update after the last preparation lands (rendering.js, `afterSettling`, which owes the release a whole quiet update, so its layout and size changes are heard first), when the last hold ends (`holdOf`), or on a revision. The controller hears preparations from its start, since one reports its end only to those that heard it begin, and a preparation a width change sets going can begin before the shift is announced; a per-window subscription missed that release and left the window open, so it put back a later change of the page's own. The one-second cap now runs only while no preparation is pending, from the window's opening or the last release, and closes a rendering update after it expires. `afterSettling` returns a withdrawal, so a page whose rendering never quiets holds no waiter per window. Probes on a bounded box with no native anchoring, a preparation growing content above the reader after the width change (main -> this branch): 1.5 s and 4 s preparations, 37 -> 237 px became 37 in Chromium and 38 -> 238 became 38 in Firefox; a page change 1.5 s after the preparation landed now moves the line (137, 138) rather than being put back. Frames asked in the 1.4 s after the cancelling input with a preparation that never lands: 0 in both.
An expired cap queues two animation frames before it closes the held place's window. A preparation that began in between cleared only the timer, which had already fired, so the window still closed while the preparation was pending and its layout moved the reader's line. Each wait now takes a turn; a preparation beginning, a later wait or the window closing ends it, and the queued close runs only on its own turn. A check of `prepared()` alone would miss a preparation that begins and lands before the stale close runs. Probe: a page whose rendering never quiets, a width change, and a preparation begun just after the cap fires that grows content above the reader 600 ms later. Before, the line moved 38 -> 238 px in Firefox and 37 -> 237 in Chromium; now it stays at 38 and 37.
leaf-agent
approved these changes
Nov 16, 2026
This was referenced Nov 16, 2026
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.
Two browser timers decided what the reader saw by how fast the machine ran. This change ends each of them on an event instead.
Holding the reading place (
SETTLING_MS, version.js). After a layout shift, such as a width change, the runtime puts the reader's place back each time late widget layout lands, and it stopped doing so after 1 s whatever was still preparing. In a probe in Chromium and Firefox, a widget that prepared for 1.5 s moved the line being read by 200 px. The window now closes after the last widget preparation has landed and one quiet rendering update has passed, when the reader's input ends the last hold, or on a revision. The 1 s cap runs only while nothing is preparing, for a page that never settles, such as an animated chart. Preparations of 1.5 s and 4 s now keep the line in place.Scroll-end fallback (80 ms and two frames, arrivals.js).
scrollendalready ends every scroll that moves the box, in Chromium, Firefox and WebKit. The fallback decides only scrolls that get none, mostly Leaf's own glides, whose last frames move less than a pixel. A glide whose last write moves nothing now ends right there, so the scroll adpress makes ends in about 145 ms instead of about 230 ms in Chromium and Firefox. WebKit's last glide frame still moves the box, so it is unchanged.What to weigh:
scrollendalone would need a backstop of about 8 s and rules predicting which inputs move nothing, so the 80 ms stays.holdRendering. The evidence for it is the probes.Max asked for this ("research #21") in a review of timers that race a slow machine. Codex reviewed it three times. It found a frame pause over 1 s that still closed the window early, a per-frame loop left running after the last hold ended, and an expired cap's queued close racing a preparation that began within it. Each is fixed, with a probe showing the line move before the fix and hold after it.
Tests:
pnpm run test:runtime(992), including a new arrivals assertion that fails on main;check:browser; seven reading-place browser tests, including the never-settles one; four scroll tests, two in Firefox.