Repository navigation
Write nothing on a scroll, and anchor the floating card, response bar and drawings to what they stand beside - #1406
Merged
Merged
Conversation
# Conflicts: # skills/leaf/assets/runtime/keyboard/shortcut-bar.js
leaf-agent
approved these changes
Sep 28, 2026
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: fixedboxes 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_UPDATEfrom the trace. What a trackpad feels is inferred from these numbers, not measured.review-a-planunless named)main→ this branchmain→ this branchundo-reachplayground, focus in its AskA plain HTML page, outside Leaf, shows the Chrome behaviour: one range highlight plus one
setAttributeper 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.jsnow states the rule and namesclassList.toggle(name, force)as the way to write a class.addandremoverewrite the attribute even when the class set doesn't change. Brought under the rule:clearAim, the trace, and visual marks (target-paint.js)hiddenanddata-lf-expandeddata-lf-thread-placementanddata-lf-placementFloating surfaces stand in the plane a scroll carries them with.
floating.jsgainsposition()andstand(). The box staysposition: fixed. In thepageplane 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 thewindowplane it is placed in pixels, as before.thread-card-geometry.js, which now returnsplane. It iswindowwhile the boundary's own edge holds the card in, andpageotherwise. The card anchors to its cluster.windowwhen the viewport, rather than the passage, holds it. The bar anchors to its passage's block.windowplane.margin-layout.jstoanchor-names.js, so rows and floats share one name per element.The card no longer clips itself to the window. Its per-scroll
clip-pathis gone.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
mainfor 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_nothingandtest_a_scroll_that_carries_the_response_bar_writes_nothingobserve the DOM through a scroll and assert no writes. Both fail on the base, which has aim, Ask, placement and badge writes.planethrough leaving, returning, an unseen cluster, and the foot.test_a_drawing_is_sent_and_replayed_as_an_ordinary_commentnow asserts that a scroll keeps the mark's node; it fails onmain.test_ask_binding_badges_do_not_cover_their_key_linenow reads only visible chips, since a chip with no room is hidden rather than removed.uv run pytest testsandnpm run test:runtimepass. 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 onmainafter 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 intest_render_drafts.py.leaf-dev stillsagainstmainshows 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
position: stickyband would make it exact, at the cost of recasting the card geometry as sticky insets.🤖 Generated with Claude Code