Skip to content

Hold every corpus page to writing only what a scroll changes - #1409

Merged
max-sixty merged 2 commits into
mainfrom
scroll-repaint
Sep 28, 2026
Merged

max-sixty merged 2 commits into
mainfrom
scroll-repaint

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Every corpus page is now held to writing only what a scroll changes. The check runs on every page, whichever module does the writing. It is the guard against the regression #1406 fixed, so no instruction or review checklist has to stand in for it. The check found one more live instance, the table of contents' lens, which this change also fixes.

The check

test_a_scroll_writes_only_what_it_changes scrolls each corpus page through a small pass (eight 30px steps down, eight back, starting a third of the way in). It runs the pass twice and reads every DOM write of the second pass through scroll_writes, in the document and each open shadow root. restless_writes fails the page when a write:

  • leaves the value it found. It changes nothing, yet while a highlight holds a range Chrome repaints the whole document for it;
  • lands on more than two steps of the pass. A state the scroll changes crosses the pass at most once each way. A position written from scroll events is written on every step, a frame behind the browser.

Evidence:

Fixes

The contents map's lens is a scroll-driven animation. Its keyframes are the lens at each scroll position where the map bends. They are set only when the map, the scroller's length or its landing band changes, and the browser interpolates between them as the page scrolls. Across the scroll on feature-gallery it matches the old lens within 0.1px. A browser without scroll timelines (Firefox before 159) draws no lens. The lens test now reads the first frame after a scroll, where the lens already stands beside the title the page scrolled to.

The banner writes only what changed. Its status, layer-reference and session-reference controls rewrote their titles, labels, dot class and words on every status render, same values included.

Guidance

  • skills/leaf/assets/AGENTS.md states the rule: the browser moves what a scroll moves, and code that runs on a scroll, a frame or a repeated reading writes only what changed. It names the test.
  • tests/AGENTS.md lists the new matrix beside the other two.

Tests

  • uv run pytest tests (1431 passed) and npm run test:runtime pass.
  • leaf-dev flake ran the check on three pages, 18 concurrent copies each, with no failure.

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

🤖 Generated with Claude Code

A scroll on any corpus page now runs a small pass twice under a MutationObserver
(`scroll_writes`), and `restless_writes` fails a place rewritten with the value it
held or written on more than two steps of the pass. Run against the runtime before
#1406 it fails on all 17 corpus pages that scroll, naming the aim paint's class
rewrite; on main it found the table of contents' lens, written on every scroll step
on three pages. The margin's card and response-bar scroll tests use the same helper.

The contents map's lens is now a scroll-driven animation: its keyframes are the lens
at each scroll position where the map bends, set only when the map, the scroller's
length or its landing band changes, and the browser interpolates between them with
the scroll. It matches the old lens within 0.1px across the scroll on
feature-gallery. A browser without scroll timelines draws no lens. The lens test
now reads the first frame after a scroll, where the lens already stands beside the
title it scrolled to.

The banner's status, layer reference and session reference wrote their titles,
labels, dot class and words on every status render, same values included; they now
write only what changed.

skills/leaf/assets/AGENTS.md states the rule (the browser moves what a scroll moves;
code on a scroll, frame or repeated reading writes only what changed) and names the
test; tests/AGENTS.md lists the matrix beside the other two.

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

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

CI’s lint job fails because Prettier rewrites the two new Lit templates. The inline suggestions match the formatter’s output; the scroll and lens tests pass locally.

Comment thread skills/leaf/assets/runtime/banner.js Resolved
@max-sixty
max-sixty merged commit f22c978 into main Sep 28, 2026
5 checks passed
@max-sixty
max-sixty deleted the scroll-repaint branch September 28, 2026 21:49
max-sixty added a commit that referenced this pull request Sep 29, 2026
)

While a CSS highlight holds a range (any page with a quoted comment),
Chrome repaints the whole document on every DOM write, including a write
that changes nothing. #1406 fixed the scroll path and #1409 checked the
corpus scroll by scroll. This PR does two things. It fails any test
whose page makes a write that changes nothing. It then fixes the writers
that check found, mostly by giving each place one writer and writing
only when the value changes.

### The sensor

`tests/write_watch.js` runs on every page the `browser` fixture opens,
in the document and in every shadow root, from before the first byte
parses. It judges writes one script at a time, meaning each
MutationObserver delivery: the microtask checkpoint that ends a
listener, a frame callback or a task. A place that ends the script with
the value it started with is reported as a browser problem, whether the
script restated the value or took it away and put it back. A child-list
write counts when it puts back nodes equal to the ones it removed
(`isEqualNode`). Judging per frame was measured and rejected, because it
flags separate genuine inputs that land in one frame.

The exemptions are few:

- `EXPECTED` lists writes made for a reason of their own: CodeMirror's
mount, Web Awesome's attribute reflection and its shadow trees, the
`lf-toc` face measure, Sortable's ghost class, and a visual-mark TODO.
- A narrow put-back rule covers a lent `tabindex` stop and the
`.lf-margin-cluster` `lf-withheld` measure.
- Empty `aria-*` reflection writes are ignored.
- `lfUnwatched(fn)` drops writes an instrument makes while it reads the
page, which includes the render gate driver's `call`.

`scroll_writes` now reads the same recorder (`window.lfWrites`).
`restless_writes` became `scroll_followers`, which only fails a place
written on every scroll step, because the sensor already catches the
same-value case.

### The writer fixes

- **`runtime/keeps.js`** is a new runtime primitive. `keeps`,
`keepsHidden` and `keepsText` moved there from `widget-elements.js`, and
about 40 importers were cut over. It compares against what the node
would read back, so a boolean or count compared raw no longer rewrites
the attribute on every pass. Reflected setters (`hidden`, `disabled`,
`title`, `className`, `classList.add`/`remove`) rewrite the attribute
even at the same value. Code uses `toggleAttribute` /
`classList.toggle(name, force)` or `keeps` instead.
- **`rendering.js` `afterScript(callback)`** runs a paint once, at the
end of the script that asked for it. It is used where a render and the
focus that lands after it would otherwise paint the moment between them:
`paintKeys`, margin contribution changes and update-focus landing,
`reach.js`, notice takedown, and gallery controls.
- **One writer per place**, applied in several areas:
- The keyboard pass owns `title`, and the version picker, Ask banner
face and approval face write only `data-lf-key-title`.
- Banner rows, traffic and data go through `setRuntimeRootAttribute`,
and root-state doors write only changes.
  - The banner toolbar's door state moved into its Lit template.
- Margin pins are decided with residency (`decidePins`/`paintPins`), so
a pin is painted even when the tokens did not change.
- The target trace paints once per frame, and the unused second writer
`traceTarget` is gone.
- **Measure without mutating.**
  - `widget-elements.js` `reserve()` measures a clone.
  - The shortcut-bar trim reads widths from rows kept out of flow.
- Key chips are measured at their anchor and written once, in whole
pixels.
- The bottom status rises over a covering panel through a stylesheet
rule, not by re-lifting it to measure it.
  - `lf-toc` shifts rows through `#fitRows`/`#fitLabels`.
- **Place holds.** `user-place.js` gains `around(mutate)` for one
synchronous mutation. It claims no `overflow-anchor`, so the scroller's
style is never written and taken back in one task. The card transcript
and the Page Map sheet use it. Its constraint, that `mutate` moves no
scroller itself, is stated in the module header.
- **Smaller fixes:**
- `syntax.js` writes no spans for a block with nothing to color. A
second pass leaves a block to the pass already in flight, and that pass
colors the text the block holds when its tokens land.
  - The thread list writes every card's `open` from one choice.
- The MCP app reports its own size and uses `field-sizing` for the
textarea.
  - `visual-review` sets shot controls before the shot connects.
- Many presenters now write only what changed: thread, margin, asks,
keyboard, chrome, and target paint.

### Behaviour that moved

- Thread cards drop the native `details[name]`. Naming a card beside an
open one made the browser close it, and then the list opened it again.
The list now owns exclusivity; a card the browser opens itself, or an
`lf-reveal`, becomes the choice.
- Ask binding-badge faces stay lent while their route stands. A face
that is not exposed turns transparent, rather than being restored and
lent again on each pass.
- A projected datum's margin key is its projection plus its datum key.
Generated rows all indexed −1, so two datums shared one host, and the
failed-surface test now expects one marker per datum (2, not 1).
- `test_render_outbox` injects its optimistic fault at `#sug-refill`
`data-lf-state`, where the paint now writes.
- Several probes that wrote and took back a value in one task now do it
across tasks or inside `lfUnwatched`.
- The examples (rust-sort, wt-merge, code-comparison,
notification-playground, data-explorer) and package widgets now write
only what changed, and the corpus has been regenerated.

`skills/leaf/assets/AGENTS.md` and `tests/AGENTS.md` state the rule
(write only what changed, one writer per place, `afterScript`) and how a
test handles an exemption.

### Testing

Full suite including nightly tests: 3433 passed, 4 failed.

- `test_substantial_options_stack_and_align_their_facts` and
`test_ask_action_binding_badges_use_the_available_card_action_seats`
also fail on `main`.
- `test_a_growing_comment_is_independent_of_page_controls` and
`test_published_example_has_the_normal_leaf_layout` pass in isolation,
so they are load flakes.

`npm run test:runtime` (182 tests), eslint and pre-commit pass.

> _This was written by Claude Code on behalf of max-sixty_

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[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