Skip to content

Move every Leaf scroll onto one glide, and end each scroll once for every reader - #5285

Merged
max-sixty merged 6 commits into
mainfrom
keys-during-smooth-scroll
Nov 4, 2026
Merged

max-sixty merged 6 commits into
mainfrom
keys-during-smooth-scroll

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Landings (m, t, a link, Back) now glide as the reading keys do, instead of riding the browser's smooth scroll, and one module decides when a scroll ends for every reader. Follows #5227.

One glide for every Leaf motion

A script's smooth scroll is slow by each engine's design and has no way to set its pace: Chromium lengthens it with the distance (about 450 ms for a page, 870 ms for three), and Firefox's spring settles in about 550 ms, both past the 300 ms that motion the user waits on may take (browser/AGENTS.md). Leaf now drives every smooth vertical move itself, as Vimium does: 140 ms of easing out, written as instant scrolls. A landing measured on a tall page took about 870 / 630 / 245 ms in Chromium / Firefox / WebKit on main and takes 140–160 ms in each here.

The handoff between the two mechanisms goes with it: the record of where a native landing was headed, the glide's takeover of a landing, and the moving map that told them apart. Glides are per box, so a landing glides each nested scroller it moves together. An auto move in a box whose CSS asks for scroll-behavior: smooth glides too.

Steps pressed while the page moves

  • After Space or PageDown, whose destination no script can read, a reading-page step waits for the browser's scroll to land and steps on from there (afterBrowserScroll), and further steps wait behind it in the order pressed. They used to be dropped. Only the inputs that set the browser scrolling (its scroll keys, a pointer, a wheel or a touch) decide whether its scroll is a key's, so a d in between doesn't change that.
  • During a wheel's or a touch's momentum, which has no destination, a step takes the box at once.
  • A step after one of Leaf's own glides measures from that glide's goal, as before.

One owner for a scroll's end

arrivals.js hears scroll and scrollend in the document, every shadow stage and any tree a module enrolls (hearScrollsIn), and ends each box's scroll once: at its scrollend, or after 80 ms and two rendering updates with no movement. A glide holds the box (holdScroll), so its many frames end the scroll once. browserScrolls says whether the browser, rather than a script, is moving a box: a scroll under way that no hold keeps open, and that has taken the box from where a script last put it. The choice bookkeeping in scrolling.js, continuity's place recording in version.js and the margin's re-placement subscribe through watchScrollEnds, and a lint rule (architecture/scroll-ends) keeps runtime code from listening to scrollend itself. A d glide no longer records the reading place on every frame: 254 ms of recordPlaces on main, 64 ms here, in Chromium on the probe page.

Behavior changes

  • Landings take about 140 ms in every engine.
  • d pressed during Space or PageDown adds to it in Chromium and Firefox. WebKit fires scrollend on each frame of a keyboard scroll, so there the step starts early and lands short (notes/browser-support.md records it with a recheck).
  • A page's own scrollend listener hears one event per frame of a Leaf landing, as it already did for the reading keys.

Testing

The typeahead test (test_keys_pressed_while_the_page_moves_act_as_if_it_had_landed) gains PageDown-then-d and PageDown-then-d d phases, and the runtime unit test for held scrolls covers ending once and telling a script's settling scroll from the browser's. Firefox and WebKit were checked by probes: Space+d, PageDown+d, wheel+d, m u and d m in each engine.

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

…very reader

Landings (`m`, `t`, a link, Back) now glide as the reading keys do, instead of
riding the browser's smooth scroll, which takes 450–870 ms in Chromium and
Firefox and has no way to set its pace. The handoff between the two mechanisms
goes with it: the record of where a native landing was headed, the glide's
takeover of a landing, and the `moving` map that told the two apart. Glides are
per box, so a landing glides each nested scroller it moves at once. An `auto`
landing in a box whose CSS asks for smooth scrolling glides too.

A reading-page step pressed while the browser's own Space or PageDown scroll
still moves the page waits for it to land and steps on from there, as the
browser's paging keys chain; it used to be dropped. A step pressed during a
wheel's or a touch's momentum takes the box at once, as the browser's own keys
do.

arrivals.js becomes the one owner of when a scroll ends. It hears `scroll` and
`scrollend` in the document, every shadow stage and any tree a module enrolls,
and ends each box's sequence once: at its `scrollend`, or after a quiet spell of
80 ms and two rendering updates. A script that writes a scroll frame by frame
holds the sequence open (`holdScroll`), replacing the page-wide `scrollGlides`
flag. The choice bookkeeping in scrolling.js, continuity's place recording in
version.js and the margin's re-placement listen there instead of to raw
`scrollend`, and a lint rule keeps runtime code from listening itself. A `d`
glide no longer records the reading place on every frame: 254 ms of
`recordPlaces` on main, 64 ms here, in Chromium on the probe page.

Behavior changes: landings take 140 ms in every engine; `d` pressed during
Space or PageDown adds to it in Chromium and Firefox.
# Conflicts:
#	browser/runtime/annotation-overlay/margin-layout.js
#	dist/kernel/kernel.json
#	dist/kernel/leaf.js
#	dist/kernel/runtime/bundle-comment-placement.js
#	dist/kernel/runtime/bundle-portable.js
#	dist/kernel/runtime/check-api.js
# Conflicts:
#	dist/kernel/kernel.json
#	dist/kernel/runtime/bundle-comment-placement.js
…de holds from its press

`browserScrolls` called any open scroll sequence the browser's once no hold kept it
open. A glide's or a landing's last write keeps its sequence open for a quiet spell
after the release, so a step pressed in that spell read the finished motion as the
browser's, took it over, and started from wherever the box stood at its first frame. A
hand that moved the box between the press and that frame was ignored, and the glide
pressed on to its goal: `test_the_reading_keys_accumulate_and_reverse` read 1447
where the user left the box at 400, under load.

`setScroll` now records where a script last put each box until its sequence ends, and
the browser moves a box only once it has left that place. The held-scroll unit test
checks both sides.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pressing d twice while the browser's own PageDown is still scrolling loses both presses (inline), so the claim that steps pressed during PageDown add up holds only for a single press. I can push the reorder and a d d test phase if you'd like.

Comment thread browser/runtime/scrolling.js Resolved
Pressing `d` twice while the browser's PageDown still scrolled lost both presses:
the first `d` keydown counted as the latest input, so PageDown's next frame stopped
counting as a key's scroll, the second `d` took the box over at once, and its glide
dropped the first `d` waiting for PageDown to land (735 px where typing slowly ends
at 1667, found by the PR review).

Only the inputs that set the browser scrolling now decide whether its scroll is a
key's: a pointer, a wheel or a touch, or one of its scroll keys. Any other key leaves
that as it was. A step pressed while others wait on the box also joins them before
anything else is asked, so waiting steps run in the order pressed. The typeahead test
gains a `d d` phase, which fails without this change.
@max-sixty
max-sixty merged commit b9203f0 into main Nov 4, 2026
6 checks passed
@max-sixty
max-sixty deleted the keys-during-smooth-scroll branch November 4, 2026 05:50
leaf-agent added a commit that referenced this pull request Nov 4, 2026
…y, since landings no longer smooth-scroll (#5311)

#5285 replaced the browser's smooth scroll with Leaf's own glide for
every landing, so nothing calls `scrollTo({behavior: 'smooth'})` on the
page any more. Four tests created their "interrupt before the first
frame" moment by wrapping that call, so since #5285 their hook never
fires:

-
`test_primary_arrival_records_a_return_place_only_when_travelling[False-True-1000-False-True]`
fails on `backRequestedAt is not defined`.
-
`test_a_thread_trip_takes_over_an_outgoing_trip_before_its_first_frame[walk|passage]`,
`test_a_visible_datum_takes_over_pending_thread_motion` and
`test_comment_follows_a_thread_current_location_instead_of_an_earlier_draft[-True]`
time out waiting for the hook.

Each test now uses one shared helper, `before_landing_frame` in
`tests/render_harness.py`, which wraps the `pushState` that adds the
trip's return stop. `arrive` commits that entry and starts the landing
in the same synchronous handoff
([`anchor-travel.js`](https://github.com/max-sixty/leaf/blob/f93acc02c72769506f84e47ea7d7b08e248edfc2/browser/runtime/anchor-travel.js#L178-L187)),
and the glide writes nothing until its first frame. So the interruption
still lands before the page moves, and it no longer depends on which
mechanism scrolls the page. Each test protects the same behavior as
before.

Verified locally on Linux: all five cases failed on `origin/main` and
pass on this branch. Under `leaf-dev flake` (18 concurrent copies each)
every case passed, and the primary-arrival test also passed every copy
at `--cpu-throttle 4`.

This leaves the failure #5188 reports open. That failure was a missing
history entry on macOS, intermittent across all four primary-arrival
cases in the nightly runs before #5285, alongside `scrollY` reading 0
instead of 200. It does not reproduce on Linux even throttled, and the
next nightly is the first `test-macos` run on the glide.

Refs #5188 — automated triage

Co-authored-by: leaf-agent <[email protected]>
leaf-agent added a commit that referenced this pull request Nov 5, 2026
…first frame (#5518)

`test_a_thread_walk_starts_one_page_trip_and_reveals_its_nested_passage`
has failed on main since #5285 because its threshold was built for the
browser's smooth scroll, and #5285 replaced that on purpose. The test
now checks the regression it was written for, a page jump in the press's
own task, instead of how far the first animation frame goes.

**Cause.** #5285 moved every landing onto Leaf's own glide: 140 ms of
cubic ease-out (`glideTo` in `browser/runtime/scrolling.js`). Even when
its first frame comes on time, that covers about a third of the trip,
roughly 390 of the 1224 px here. Native smooth scroll started slowly, so
`firstPage < 100` used to tell a jump from a smooth start, but against
the glide it can't. On this runner the frame after `t` came 70–90 ms
after the press, so the first page `scroll` event already read 1025–1146
px, and the frames after it eased monotonically to 1224.

**Change.** The old bug was `scrollIntoView` moving the document to its
nearest edge before the centred landing, and that move happens in the
press's task. A `keydown` capture listener registered after the
runtime's reads the page, the rail and the local scroller once the walk
has handled `t`. At that point the nested scrollers have moved and the
page has not. Once the passage is centred, the test also checks that the
page's scroll positions only ever increase, so the page makes one trip.
The interface and #5285's intent are unchanged; only the test moved.

**Verification.** On current main the test fails as reported
(`firstPage: 1025`). With this change it passes three runs in a row.
Reintroducing the nearest-edge reveal on the page (dropping `if (box ===
targetScroller) inside = false;` in `innerMoves`) makes the new check
fail with `page: 830`.

<details><summary>Not changed here: the glide's clock and a late first
frame</summary>

`glideTo` starts its clock at the press. When the press's work holds the
next frame back, as it did here by 70–90 ms, most of the ease runs out
before anything is drawn, and the first frame that moves the page shows
it about 90% of the way there. The first tick's rAF timestamp also came
before the press (about 2845 ms against 3011 ms), so it was clamped to t
= 0 and wrote no movement. Starting the clock at the first frame would
change how long every landing and reading key takes, which is a product
decision for #5285's line of work and not part of this test repair.
Whether that delay also happens on a desktop, rather than this headless
runner, hasn't been measured.

</details>

Closes #5476 — automated triage

Co-authored-by: leaf-agent <[email protected]>
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