Skip to content

Keep a Moment's landing on a saved element over the tree's older readings - #2546

Merged
max-sixty merged 1 commit into
mainfrom
agent-a4225ca3a4118894d
Oct 12, 2026
Merged

max-sixty merged 1 commit into
mainfrom
agent-a4225ca3a4118894d

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A Moment that names a saved-tree node in lf-trace now always lands that row inside the tree's own scroll box and the page's reading band. This is item #53 of the Lit follow-up round (the round's own numbering, not a GitHub issue).

What was undoing the landing

Two place keepers restored a reading recorded before the click, after the Moment had already landed:

  • Continuity's shift restore (version.js, restoreShifted). Opening the tree hands its reading region from the point inspector to the tree's own scroller. The resize observer announces that shift a frame after the landing, and the restore put the tree back at its pre-click reading. Now landing-scroll.js numbers landings and keeps the last that moved each box (landedSince). version.js records that count with each region reading, and a shift restore leaves alone any box a landing has moved since its reading was taken. The rule covers every landing through scrollIntoView or scrollIntoReadingBand, not only lf-trace's.
  • lf-trace's own tree place, restored on every toggle event, which fires a frame after the open. It moved the tree back after a navigation's landing. Under smooth motion even a zero-length move cut the landing's animation short, which is the "tree scrolled 31px" symptom. The restore now runs synchronously, and only on the reader's own press on the "Saved elements" summary.

A third defect: #visitMoment asked whether the row was inside the window, so a row inside the window but below the tree's box never moved. A saved element now lands with nearest through every box that scrolls it. That moves nothing that already shows the row.

Why it passed on some runs

When the Moment's checkpoint differed from the one shown, #visitMoment waited for the new image to decode. That wait usually outlasted both restores, so the landing came last and stood. When the checkpoint was already shown, the landing came first and was undone whenever either keeper had a reading to restore. The test makes this deterministic: it lands on the checkpoint already shown, after the reader has scrolled and closed the tree, and runs in both motions. Smooth motion exposes the toggle restore and reduced motion exposes the shift restore. I confirmed that each half of the fix fails its own motion when reverted.

Behaviour changed

  • A Moment on a saved element shows its row in the tree and the page, every run.
  • Pressing the tree's summary restores that checkpoint's reading before the next paint, rather than a frame later. An opening by navigation or find-in-page no longer restores it.
  • A shift restore in the runtime no longer moves a box that a landing moved since its reading was recorded.

Line deltas

  • Hand-written source: +79 / −31, so net +48 (landing-scroll.js +23/−8, version.js +22/−4, lf-trace.js +34/−19).
  • Tests: +110 (tests/test_render_playwright_trace.py, one test run in both motions).

Left open

  • A native scroll, such as find-in-page opening the closed tree onto a match, is not a landing, so continuity's shift restore can still undo it. The independent reviewer simulated this; it is not a regression. The more general signal is a scroll recorded between the reading and the shift. It needs a way to tell a navigation apart from the resize's own clamp.
  • lf-trace's per-checkpoint tree places and continuity's region reading both keep a place for the same region. On a summary press they agree today only because focus on the summary makes continuity's restore a no-op.

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

…ings

A Moment that names a saved-tree node in lf-trace now always shows that row
inside the tree's own scroll box and the page's reading band (#53).

Three things kept it from doing so:

- Continuity's shift restore (version.js) undid the landing. Opening the
  tree hands its reading region from the point inspector to the tree's own
  scroller, and the resize observer announces that shift a frame after the
  Moment has landed. The restore then put the tree back at the reading
  recorded before the click. landing-scroll.js now numbers landings and keeps
  the last that moved each box (`landedSince`); version.js records the count
  with each region reading, and a shift restore leaves a box that a landing
  moved since its reading was taken. This applies to every landing, thread
  travel into a newly bounded region included.
- lf-trace restored the checkpoint's tree place on every `toggle` event,
  which fires a frame after the open. After a navigation's landing it moved
  the tree back, and under smooth motion even a zero move cut the landing's
  animation short (the tree stopped about 30px in). The restore now runs only
  on the reader's own press on the summary, synchronously, so lf-trace no
  longer moves the tree under a Moment, a thread or find-in-page. A native
  scroll, such as find-in-page's, is not a landing, so continuity can still
  restore over it.
- #visitMoment asked whether the row lay inside the window, so a row inside
  the window but below the tree's box never moved. A saved element now lands
  with `nearest` through every box that scrolls it, which moves nothing that
  already shows it.

Why it passed on some runs: when the Moment's checkpoint differed from the
one shown, #visitMoment awaited the new image's decode, which usually
outlasted both restores, so the landing came last. When the checkpoint was
already shown, the landing preceded both restores and was undone whenever
either had a reading to restore. The test lands on an already-shown
checkpoint, after the reader has scrolled and closed the tree, in both
motions: smooth motion exposes the toggle restore, reduced motion the shift
restore.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit d25a3b4 into main Oct 12, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-a4225ca3a4118894d branch October 12, 2026 08:04
max-sixty added a commit that referenced this pull request Oct 12, 2026
… places in continuity (#2560)

The runtime now has one rule for whose a scroll position is, and one
keeper for the reader's place in lf-trace's saved-element tree. This is
item #56 of the Lit follow-up round (the round's own numbering, not a
GitHub issue). It follows #2546.

## One rule for the reader's scrolls

A box stands where the reader chose, or where layout put it.
Continuity's shift restore (`version.js`, `restoreShifted`) should undo
only layout's moves. #2546 counted Leaf's landings as the reader's
choices. That missed the browser's own scrolls, such as find-in-page
opening a closed tree onto its match, and counted a restore's focus
reveal as a choice.

The platform already draws this line. A scroll sequence ends with
`scrollend` whoever started it: wheel, keys,
`scrollTo`/`scrollBy`/`scrollTop`, smooth motion, `scrollIntoView`, and
fragment navigation, including one that opens a closed `<details>`. A
clamp as content shrinks, a scroll-anchoring adjustment, and a
`<details>` reopening at the offset it kept end none. I measured each
case in headless Chromium; the reviewer confirmed the ordering in
WebKit.

`scrolling.js` now owns the rule, and its header states it:

- A `scrollend` on a box is the reader's choice (`chosenSince`).
- A place keeper's write returns the reader to a place they already had,
so it records where it left each box (`placeKept`). A sequence that ends
there is the keeper's. This covers `restorePlace`, `placeKeeper`'s
correction, and continuity's page-band move.
- A landing in smooth motion counts from its start, since layout it
caused can be announced before the motion ends.
- Continuity takes a reading at each `scrollend` as well as on `scroll`.
WebKit, and Chromium for touch, end a scroll frames after its last
`scroll` event, and without that reading every reader scroll would look
newer than its own reading.

`landing-scroll.js` loses its own landing counter.

## One keeper for the saved-element tree

lf-trace kept a place per checkpoint for its "Saved elements" tree and
restored it on a summary press. Continuity restored the same box from
its region reading. The two agreed only because focus on the summary
made continuity's restore a no-op.

A region can now show one subject of several in turn. Its owner replaces
the body's contents inside `showReadingSubject(id, subject, render)`
(`reading-regions.js`). Continuity keeps a reading per subject and
returns the reader to it, both when the subject shows and when the tree
opens. A region whose body is a closed `<details>` is concealed, so
continuity no longer records a closed tree's reading. That reading had
only the enclosing trace as its landmark, and restoring it scrolled the
tree to its top. lf-trace drops `#treePlaces`, `#treeScope`, its scroll
listener and its summary press handler. `readingRegion` leaves
`widget-api.js`, since nothing imports it now.

## Behaviour changed

- (c) When find-in-page opens the closed tree onto a match, the match
stays shown; before, the shift restore put the tree back where the
reader had left it.
- (b) A restore's own scroll, its focus reveal included, is never the
reader's choice, so the next frame's shift restore still corrects that
box.
- (a) Opening the tree, or returning to a checkpoint, puts the reader
where they left that checkpoint's tree, through the runtime's keeper. A
press now reopens the tree natively. For the same checkpoint, the
browser keeps the offset. If the checkpoint changed while the tree was
closed, the restore lands one frame after the opening rather than before
its paint.
- Focus on a closed tree's summary no longer makes the tree the region
whose reading continuity records.
- The per-checkpoint readings now live as long as the tree's reading
region, so a trace that leaves the document and comes back starts
without them; lf-trace's own map had kept them until the archive
changed.

## Tests

- `test_trace_tree_opened_by_the_browser_keeps_its_match` (c) fails on
`main`: the row ends 572px down in a tree showing 54–154px. Headless
Chrome has no find bar, and Leaf intercepts fragment navigation, so the
page makes the find's two moves itself: it opens the tree and scrolls
the row into view natively.
- `test_trace_tree_opens_at_each_checkpoints_reading` (a) checks that a
checkpoint left scrolled in its tree reopens there after another
checkpoint was scrolled elsewhere and the tree was closed between. It
fails if the subject's reading is not adopted (488 vs 40) or if the
closed tree is not concealed (482 vs 40).
- `test_a_split_drag_keeps_a_panes_reading`, in Chromium and WebKit, has
the reader wheel-scroll a pane and then drags the split frame by frame,
with scroll anchoring off as in Safari. It fails if a keeper's writes
count as choices (1487px instead of 102px), and in WebKit it fails if
continuity takes no reading at the scroll's end (51px instead of 101px).
WebKit leaves the restored passage about 5px off on `main` too, so the
test allows 8px.
- (b) did not fail on `main` in any run I made. There, `restoreShifted`
re-records right after its restore, so the counted reveal never predates
a reading. The split-drag test guards the general form under the new
rule.
- The #2546 saved-element tests share a setup helper with the new ones
and pass in both motions.

## Line deltas

- Hand-written source (JS, excluding Markdown): +177 / −98, net +79
(`scrolling.js` +43, `version.js` +61/−13, `reading-regions.js` +28/−4,
`lf-trace.js` +20/−56, `landing-scroll.js` +6/−15, `reading-place.js`
+11/−6, `user-place.js` +7/−3, `widget-api.js` +1/−1).
- Tests: +160 / −23, net +137.

> _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.

2 participants