Skip to content

Fail any write that changes nothing, and fix the writers it found - #1418

Merged
max-sixty merged 23 commits into
mainfrom
scroll-repaint
Sep 29, 2026
Merged

max-sixty merged 23 commits into
mainfrom
scroll-repaint

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

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

max-sixty and others added 22 commits September 28, 2026 18:34
…, fixtures

The trace a margin entry casts paints once per frame from where the gesture
ends, rather than clearing on a close and repainting when the returned focus
names the same target in the same task. page-geometry's unused traceTarget,
a second writer of the same box, is gone.

The thread list writes every shown card's disclosure from its one choice and
the cards drop the native `name`: naming a card beside an open one made the
browser close it and the list open it again. A card the browser opens itself
becomes the choice. A folded row's Draft mark repaints in the frame, so a send
paints the row once from the message rather than once for the emptied box.

Syntax highlighting skips a block whose tokens are still on their way, so a
message rendered twice in a turn no longer writes the same spans twice.
lf-toc restates no href when a destination's id changes; lf-targeting and the
playground's copy control say only what changed.

The MCP app reports its own size instead of the SDK's reading, which set the
root's height to max-content and back on every resize; a complete-page payload
decides the frame's visibility before writing it; an unchanged snapshot keeps
its tree. A test now asserts the size report reaches the host.

Test fixtures and probes that restated or took back a value now say only what
changes: fixture widgets write through keeps, rebuilt nodes are marked as
different, scrub positions and a sidebar reading run as separate tasks, the
thread-filter fixture reuses its rows, and the thread test no longer asserts
the removed `name` attribute.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Each place the keyboard layer and the page chrome wrote and took back in one
task now gets its final value once:

- Shortcut bar trim: a row off the line keeps its width out of flow and
  unseen (chrome.css), so the trim works out which rows fit from the widths
  they have instead of showing every row and hiding the ones that wrap.
- Bottom status: rises over a covering thread panel's foot by a stylesheet
  rule keyed on the panel's modal state; syncLayout states only the foot's
  height instead of resetting and re-lifting the status to measure it.
- Key chips (Go-to hints, target-picker hints, Ask chips): measured at their
  anchor off where they stand (geometry.js boxAt) and written once, to whole
  pixels, which the inline style reads back exactly.
- Ask binding-badge faces stay lent while their route stands; one that is not
  exposed is transparent rather than restored and lent again each pass.
  Exposure reads the whole hit-test stack, so it reads the same worn or
  withheld.
- Version picker: aria-expanded has one writer; a comparison presents its
  pending base in one presentation rather than unlit then lit.
- Status disclosure: aria-expanded through keeps.
- Auxiliary surfaces: the covering boundary hands over from one surface to
  the next in one step, with one inert record for the boundary, and other
  surfaces stay out of the background their own slides own.
- Slide: a skipped exit writes no leaving marks.
- Notices: taking a notice down is drawn at the end of the turn, so a walk
  that hides one and an acknowledgement that shows the next write it once.
- Banner controls: showBannerControls moves several contributions in one
  paint; touch controls use it.
- Composer: the suggest mode renders after the bar stands on the anchor; a
  stored draft whose passage does not stand opens nothing.

Tests that wrote and took back in one task now do it across tasks (the shot
presses, the targeting arm/reset, the nested modals, the walk-position and
spent-control probes, the pulse dot class), and the shortcut row probes skip
rows off the line (visibility).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
- A synchronous place hold (`around`) claims no anchoring: inside one task only
  reflow moves a scroller, so its correction pays for every movement since the
  reading and absorbs what the browser's anchoring did in a forced layout. Only a
  hold that spans tasks sets `overflow-anchor: none`, and a hold replacing another
  writes the style once. The card transcript and the Page Map sheet use `around`.
- Margin contribution changes reach the projection once per task (microtask), so a
  publication updating several contributions or a widget moved between parents
  paints one state. A registration asked for a control or layout settles first.
- `paintKeys` reflects once per task, so a render and the focus that lands after it
  do not paint the moment between them. A refused scope is reported and the rest
  still paint; the ambiguity test now reads the paint after a microtask and
  consumes the reported refusal.
- A projected datum's target key is its projection and datum key: generated rows
  all indexed -1 among authored siblings, so two datums shared one margin host.
  The failed-surface test now expects one marker per datum.
- Margin options open from the entries' reading and render once, already open.
- Holds are decided whole, then written; a reaction lands the user once; a
  settled suggestion asks its margin after its fold; a reading region's cue leaves
  at the end of the task, so a moved host keeps it.
- Tests: helpers stop restating a lent tabindex, the passage sweep unhides only
  page content, and the dense-margin fixture updates without forcing a render per
  contribution.

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.

A pending syntax pass can overwrite newer code text during a live update; see the inline reproduction.

Comment thread skills/leaf/assets/runtime/syntax.js Resolved
…s land

The tokenizing guard left a second pass to the one in flight, which then wrote
the text it had read before the await over a block rewritten meanwhile. The pass
now re-tokenizes when the text or the language changed during the await.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 3503cfa into main Sep 29, 2026
7 checks passed
@max-sixty
max-sixty deleted the scroll-repaint branch September 29, 2026 07:21
max-sixty added a commit that referenced this pull request Sep 29, 2026
…ard without clearing it (#1419)

Two load-only failures the write sensor from #1418 reported in full
nightly sweeps, both fixed at the writer, and the sensor's visual-mark
exemption removed.

**Sub-pixel style writes.** The comment's visual mark was never placed
twice. Its position was written from raw floats, and a length recombined
from client coordinates and a fractional scroll offset (`documentPoint`)
differs below layout precision from pass to pass on a box that has not
moved. Chrome queues a style mutation for that, but serializes the
length to six significant digits, so the attribute text reads unchanged.
`keeps.js` now owns `atLayoutPrecision` (round to 1/64px) and `layoutPx`
(its CSS text), with the rule in its header, scoped to style properties
the browser re-serializes; custom properties keep their text verbatim
and fall outside it. Every writer of a measured length to such a
property uses them: the aim, trace and mark boxes (one `standOver` in
`target-paint.js`), the floating boxes, drawings, the thread card's
clip, the margin lanes' clip, the design-mode name, the page search's
matches and the contents map's lens. A shaped paint rounds its size and
clone offsets the same way, so a repaint of an unmoved shape finds the
clones it holds equal.

**Thread card cleared and re-placed.** Placing an open card afresh (a
thread transition, or the card moving to another margin entry) went
through the close path, which deletes `data-lf-plane`, the position and
the opacity, and the next placement wrote them back. It now only forgets
the previous placement (`forgetThreadPreviewPlacement`): it drops the
hold and supersedes any placement in flight, and the card keeps its spot
until the new one lands. Clearing is for closing
(`unplaceThreadPreview`).

That leaves "not yet placed" as one declared fact: `chrome.css` keeps a
card without `data-lf-thread-placement` at opacity 0 and out of reach,
in place of the inline opacity the close path used to write. Without it,
a card opened while the positioning module was still loading stood fully
drawn and pressable at the top left
(`test_a_thread_card_is_unseen_until_its_first_placement_lands`).

`floatingPlacement.position()` drops an answer a later placement
superseded before it writes the plane or the way of standing, so a stale
answer can no longer put the card back in the page plane at the newer
placement's spot (`tests/runtime/floating-placement.test.mjs`).

The contents map's face trial and the margin's withheld-row measure keep
their exemptions in `tests/write_watch.js`: each chooses a state by
applying it to the live element, and neither has a mutation-free measure
(a `visibility: hidden` row still adds scrollable overflow).

Full suite with `--run-nightly`: 3436 passed, 3 failed. Two pass in
isolation; `test_substantial_options_stack_and_align_their_facts` fails
the same way on a tree without this branch. None is a write finding.
`npm run test:runtime`: 183 pass.

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

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

---------

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