Skip to content

Write nothing on a scroll, and anchor the floating card, response bar and drawings to what they stand beside - #1406

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

max-sixty merged 5 commits into
mainfrom
scroll-repaint

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Document scrolling on a page with comments stuttered. Two things caused it. Leaf's scroll path wrote to the DOM on every scroll event, and while a CSS highlight holds a range, Chrome repaints the whole document for any write, the same value included. And the thread card and the response bar were position: fixed boxes that script re-placed on every scroll, so they trailed the compositor-scrolled text by a frame. After this change a scroll writes nothing to the DOM unless something actually moved, and the floating card, response bar and drawings are anchored to what they stand beside, so the browser carries them with the page.

Measurements

Headless Chrome at 1440×900, 80 synthetic wheel steps of 10px. The latency is Chrome's median FIRST_GESTURE_SCROLL_UPDATE from the trace. What a trackpad feels is inferred from these numbers, not measured.

Case (review-a-plan unless named) Latency main → this branch Full-document paints main → this branch
No card open 13.9 → 11.0 ms 82 → 2
Thread card open 47.5 → 14.1 ms 161 → 6
Response bar up over a selection 47.5 → 13.8 ms 160 → 4
undo-reach playground, focus in its Ask 13.6 → 14.0 ms 79 → 4 (frames with a DOM write 160/220 → 2/220)

A plain HTML page, outside Leaf, shows the Chrome behaviour: one range highlight plus one setAttribute per scroll event gives 80 paints and 11 → 27 ms. Without the highlight it gives 1 paint.

What changes

The scroll path writes only what changed. widget-elements.js now states the rule and names classList.toggle(name, force) as the way to write a class. add and remove rewrite the attribute even when the class set doesn't change. Brought under the rule:

  • clearAim, the trace, and visual marks (target-paint.js)
  • the shortcut bar's hidden and data-lf-expanded
  • data-lf-thread-placement and data-lf-placement
  • the Ask ring
  • Ask binding badges: previously torn down and re-worn on every pass. A badge whose control is off screen is no longer worn only to be measured away.

Floating surfaces stand in the plane a scroll carries them with. floating.js gains position() and stand(). The box stays position: fixed. In the page plane it is anchored with CSS anchor positioning, as the margin's rows already are, to the element it stands beside, and its spot is written as insets from that anchor. The browser then carries it through every scroll that moves the anchor, and a placement after that scroll finds the same insets and writes nothing. In the window plane it is placed in pixels, as before.

  • The card reads its plane from thread-card-geometry.js, which now returns plane. It is window while the boundary's own edge holds the card in, and page otherwise. The card anchors to its cluster.
  • The response bar reads its plane from its shift limiter: window when the viewport, rather than the passage, holds it. The bar anchors to its passage's block.
  • Because the box stays fixed, a scroll into view or a focus inside it still never scrolls the page.
  • A box held at a reading region's edge counts as the page's, since the page carries the region.
  • A box under a transformed ancestor, whose containing block is not the viewport, stays in the window plane.
  • An anchor lost between placements stands the box off screen, as the rows fall back, until the next placement.
  • Anchor naming moves from margin-layout.js to anchor-names.js, so rows and floats share one name per element.

The card no longer clips itself to the window. Its per-scroll clip-path is gone.

  • The card moves down the z-index ladder to 8920, under the banner and the bottom bar, so it passes under them the way the text does, blurred behind the veil rather than cut at its edge.
  • The thread transition moves to 8910 to stay under the card.
  • A reading region still clips the card.
  • A scroll leaves the card's height cap as it is. A card takes a new cap only when its contents change (a turn arrives, a draft grows), or when the new cap would cut it.

Paint in the document plane is not clipped to the window. Target paint uses the new pagePlaneRect. The page's own clipping boxes and a stuck root header still cut it; the window no longer does, because that cut moved with every scroll.

Drawing marks are anchored too. Each mark is fixed and anchored to what it was drawn on (or to main for a whole-page drawing). A scroll no longer rebuilds every mark's SVG, and strokes still stay out of the document's scrollable overflow.

Ask binding chips stand in the document plane. The chips are kept across passes, and a chip with no room is hidden rather than removed.

Tests

  • test_a_scroll_that_carries_the_card_writes_nothing and test_a_scroll_that_carries_the_response_bar_writes_nothing observe the DOM through a scroll and assert no writes. Both fail on the base, which has aim, Ask, placement and badge writes.
  • The geometry tests now assert plane through leaving, returning, an unseen cluster, and the foot.
  • test_a_drawing_is_sent_and_replayed_as_an_ordinary_comment now asserts that a scroll keeps the mark's node; it fails on main.
  • test_ask_binding_badges_do_not_cover_their_key_line now reads only visible chips, since a chip with no room is hidden rather than removed.
  • uv run pytest tests and npm run test:runtime pass. The nightly selection over the widgets, margin, navigation, anchors, aim, options, threads, drafts, controls, drawing and chrome-contract files passes except four tests that fail identically on main after Keep the shortcut bar to one row #1404: test_ask_action_binding_badges_use_the_available_card_action_seats, test_a_growing_comment_is_independent_of_page_controls, and two in test_render_drafts.py.
  • leaf-dev stills against main shows no visible change at rest. It records sub-pixel differences only (at most 18/255 on one channel), in the card's shadow under the bottom bar and the composer's antialiasing.

Left as they are

  • A card whose target sits in a scrolling pane still rewrites its clip at the pane's edge on each scroll of that pane.
  • While a scroll leaves the card under a larger cap than the room, growth can stand past the boundary for one frame until the next placement.
  • Crossing between the planes, where the boundary starts or stops holding a box in, is decided on the main thread, so that one frame can overshoot or lag. A position: sticky band would make it exact, at the cost of recasting the card geometry as sticky insets.

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

🤖 Generated with Claude Code

@max-sixty
max-sixty merged commit ad08cdd into main Sep 28, 2026
5 checks passed
@max-sixty
max-sixty deleted the scroll-repaint branch September 28, 2026 20:41
max-sixty added a commit that referenced this pull request Sep 28, 2026
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:

- With the runtime from 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 step
on `feature-gallery`, `pr-walkthrough` and `security-boundary`.
- Eight corpus pages don't scroll far enough for the pass and are
skipped.
- The margin's card and response-bar scroll tests now use the same
helper.

## 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](https://claude.com/claude-code)

---------

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