Skip to content

fix: end a reader's wheel sequence when Chromium applied the scroll before the wheel event - #5931

Merged
leaf-agent merged 1 commit into
mainfrom
fix/issue-5926
Nov 13, 2026
Merged

leaf-agent merged 1 commit into
mainfrom
fix/issue-5926

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

Chromium can apply a wheel's scroll before it dispatches the wheel event. #5834's startReaderScroll therefore recorded the box already at the scroll's goal. When the scroll's own scrollend arrived, the box still stood where the input had "found" it, so awaitsReader took that event for the end of some other scroll. The reader's sequence then stayed open for the 80 ms quiet spell after the scroll had actually ended. If a reply was drawn above the reader during that spell, the keep that holds their place (holdUserPlace in user-place.js) saw browserScrolls as true and yielded. The reply then took back 195px of the reader's 300px wheel.

A trace of the failing case shows the order: the wheel event fires with scrollTop already at 2679, then scrollend is heard with awaitsReader true, the keep runs 50 ms later with browserScrolls true, and the sequence ends 40 ms after that. On #5834's parent, the keep wrote the place back at that point.

With this change, a reader's input starts from where the page last heard the box stand (its last scroll event, a Leaf setScroll or a stop) whenever the box has moved since without the page hearing about it. That keeps #5834's intent in both of its cases:

  • Firefox, which applies the input's scroll after the input: the box hasn't moved unheard, so the behavior is unchanged.
  • A layout clamp as a log loses entries: the clamp keeps the box's end where the page last heard it, so its scrollend still ends nothing of the reader's.

Behavior changed: after a wheel in Chromium, a reply drawn above the reader just after the scroll ends is held in place again, as before #5834.

Verification:

  • test_the_page_holds_still_under_the_user[wheel-reply-above-chromium] fails on main 5606fc2c9 (moved -105.0px) and passes with this change. All wheel/smooth cases of that journey pass in both engines; the two Firefox smooth cases stay xfailed as before.
  • A new case in tests/runtime/arrivals.test.mjs fails before the change and passes after. The full runtime suite passes (965 tests).
  • I also ran the browser tests Keep a log's end with the card's keeper, and treat the reader's scroll as theirs from the input #5834 added or changed: 108 of 109 pass. test_obligations_sharing_context_keep_their_source_identity failed, but it fails 2 of 4 runs on main without this change too.

Closes #5926 — automated triage

…efore the wheel event

Chromium can apply a wheel's scroll before it dispatches the wheel event, so
`startReaderScroll` recorded the box already at the scroll's goal. The
scroll's own `scrollend` then arrived with the box still where the input
"found" it, so `awaitsReader` took it for some other scroll's end and the
reader's sequence ran on for the 80 ms quiet spell after the scroll had
ended. A keep holding the reader's place across a reply drawn above them in
that spell (user-place.js, `holdUserPlace`) saw `browserScrolls` and yielded,
so the reply took back 195px of a 300px wheel.

The input now starts from where the page last heard the box stand (its last
scroll event, Leaf write or stop) when the box has moved since unheard. A
layout clamp keeps the box's end where it was last heard, so its scrollend
still ends nothing of the reader's; where the browser applies the input's
scroll after the input, as Firefox does, nothing changes.

Behavior changed: after a wheel in Chromium, a reply or revision drawn above
the reader within ~80 ms of the scroll ending is held in place again, as
before #5834.

Closes #5926
@leaf-agent
leaf-agent merged commit 5457819 into main Nov 13, 2026
6 checks passed
@leaf-agent
leaf-agent deleted the fix/issue-5926 branch November 13, 2026 08:50
max-sixty added a commit that referenced this pull request Nov 14, 2026
…cond reading

#5931 made the reader's sequence record where the input found the box as where the page last heard it stand, since Chromium can apply a wheel's scroll before it dispatches the wheel. `aimScroll` still read `box.scrollTop` at the input for `readerScroll`'s `top` and `fromEnd`, a second copy of that fact which disagreed with the corrected one: a wheel up a log entries stream into, applied before its event, would have stood "where the input found it" at its end, and the end keeper would have put the reader back at the end. `startReaderScroll` now returns where the input found the box, and `aimScroll` takes its `top` from that. A runtime case holds it: a box heard at 150 and moved to 100 unheard is found at 150.
max-sixty added a commit that referenced this pull request Nov 14, 2026
…it (#5863)

A scroll write cancels the scroll the browser is about to apply for the
reader's wheel or key, and Firefox applies that scroll a frame or more
after the input. #5834 made the input open the box's scroll sequence
(arrivals.js, `startReaderScroll`), so a writer can know the reader has
the box before it moves. This PR has every writer that was still
cancelling the reader's scroll, or taking their place, ask that record.
It began as the fix for the answer placement below, and grew with a
review of "one owner for who controls a box's scroll", which ran the
other writers and found more. The review's verdict was to share the
facts the sequence record already holds, not to build a second owner or
one rule in `setScroll`: served as a scratch copy, that rule dropped
corrections other writers owe and left a log's tail 1,407px below the
window.

**Answer placement** (thread-card.js, `#fitAnswer`): a reader at the end
of a card's transcript, or of the panel's thread view, who wheeled up as
the answer to their turn arrived was put back, since the placement read
the box at its old end and then moved their turn into sight.
`readerScrolls(box)` says whether the reader's input has the box
scrolling; the placement treats that reader as standing where the scroll
takes them, at the read and again before its delayed write. A reader at
the end whose wheel or key down moves nothing, as the answer arrives
within that scroll's quiet spell, now gets New reply without their turn
being moved into sight. Probes (Firefox): card 1110 → write 1148, wheel
lost; now 1110 → 810. Panel 699 → 729; now 699 → 399.

**End keeper** (scrolling.js, `followEnd`): it let go only of an input
heading up, so its writes cancelled a wheel across a log's long lines
while entries streamed in (Firefox: scrollLeft stayed 0).
`readerScroll(box)` says which way the reader's input heads the box,
down, across or up, and where its first input found it, as the reader's
sequence records it (arrivals.js, `startReaderScroll`, which since #5931
takes where the page last heard the box, as Chromium can apply a wheel
before dispatching it); a wheel counts by the axis it moves most along,
so a trackpad's drift down doesn't hold the end. While a scroll across
or up runs, the keeper writes nothing. When it ends, at the first
reading of the drawn box, a reader who stood at the end is put back
there only where Leaf started no move meanwhile (as `g g` would) and the
scroll moved the box nowhere up or down: across, every such move is
layout's; up, the box stands where the input found it, from its top or
from its end (#5834's rule). No reading during the scroll tells the
reader's moves from layout's: an attribution by scroll events, tried
here, passed locally and failed on CI's Chromium, where a reading
between frames found the box already moved by PageUp before PageUp's own
scroll event.

**Foot keeper** (scrolling.js, `keepFoot`): the panel's thread view
moved as it gave up room during a wheel, cancelling the wheel in Firefox
(from 400, a wheel of 200 up with 100px of room taken ended at 500, not
300). It now owes the move until the reader's scroll ends, and drops it
where that scroll ended at an edge, as Home's does, or where Leaf
started a move meanwhile, as `g g` does.

**Keys on controls** (scrolling.js, `scrollsFor`; control-selectors.js):
every control was read as taking every scroll key, so PageUp on a link,
radio or button, or ArrowUp on a button, in a streaming log opened no
reader scroll and the keeper cancelled it in Firefox. A link takes Enter
alone, a plain press Enter and Space, a radio its arrows; the browser
scrolls for the rest. The glide stop now uses the same predicate, so
Space or an arrow on a radio, select or range no longer stops a Leaf
glide, and a scroll key on a link or button does.

**Place keep** (user-place.js, `holdUserPlace`; landing-scroll.js,
`scrollIntoView`): the keep gave up for a scroll chosen in any box; it
now yields only to a choice in a box scrolling the place it keeps. And a
restore's reveal of the control the reader was on counted as their
choice, so a window resized while a diff's new source drew left that
control 262px down; `scrollIntoView` takes `kept` for a reveal that
returns the reader to a place they had, which `restorePlace` passes.

Left as they were: touch drags, which no engine here can drive in
Firefox; ArrowLeft and ArrowRight, which Leaf doesn't count as scroll
keys; a wheel moving up but more across, which counts as across, so the
keeper puts the reader back at the end after it; a reader at a capped
log's end whose input up moved nothing while the log lost its oldest
entries and gained new ones in one change, whom the keeper stops
following, as on main; and continuity's correction for the end of a
restore's scroll that layout moved on (`writing`/`ownEnd` in
version.js), which no case showed failing for another consumer.

Tests: the streamed-log test gains "PageUp on a link" and "wheel
across"; the log test's refill case gains a wheel across;
`test_a_wheel_as_the_thread_gives_up_room_moves_it_as_far_as_without` is
new;
`test_a_wheel_up_a_card_as_its_answer_arrives_goes_where_it_takes_the_reader`
covers the answer placement. Each fails on the runtime without its fix,
in Firefox (the answer placement's in Chromium too), and passes with it.
Unit tests cover `scrollsFor`, `readerScroll` and the per-box keep. The
navigation, hidden-log, refill, trim-and-append, Home and resize cases
ran as probes in both engines, with the reviewer's reproducers from all
three rounds. Locally, the focused browser selection (bounded logs, card
and panel threads, keys, glides, reading places and place keeps) passes
except `test_an_open_view_covers_the_page_beneath_it`, which fails
intermittently on main too (#5744). CI's `test` at 54a6771 failed two
server-lifecycle tests in `tests/model/test_session_lifecycle.py`
(`test_a_prompt_says_why_a_page_did_not_start_and_tries_again[port
held]`,
`test_a_prompt_serves_only_a_page_its_session_still_means_to_serve`),
where a prompt's server start did not become ready in time; this PR
changes no Python, both pass locally on this branch, and another PR's
run in the same quarter-hour failed other tests of that module the same
way, so they are inherited.

> _This was written by Claude Code on behalf of max-sixty_
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.

test_the_page_holds_still_under_the_user[wheel-reply-above-chromium]: the page takes back the reader's wheel since #5834

1 participant