Skip to content

Run every rendering callback in one pass per frame - #1154

Merged
max-sixty merged 2 commits into
mainfrom
one-render-loop
Sep 25, 2026
Merged

max-sixty merged 2 commits into
mainfrom
one-render-loop

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Leaf's chrome and geometry had about 20 owners, each asking the browser for its own animation frame. Work one frame callback queued for another ran a frame later, so anything that follows the page — target boxes, the design-mode legend, the action bar — painted one frame behind a repaint that moved the page, and the settled reading (#1145) needed an extra frame to say so.

runtime/rendering.js now owns the one frame Leaf asks for:

  • nextRender queues into one pass per frame. Asked for from inside the pass, it runs in that pass, before the frame paints; asked for anywhere else (an input handler, a ResizeObserver delivery), it runs in the next frame's pass. A chain that keeps asking stops after eight generations and finishes on the next frame.
  • The pass waits one microtask step between callbacks, so a publication a callback makes has rendered before the next callback reads the page, and reports a callback's error without stopping the owners after it.
  • nextFrame is for a step that must not run in the pass that asked for it. The scroll glide (navigation.js), the place-hold follow loop (user-place.js) and the interaction gallery's frame pause move onto it, since each re-asks from inside its own callback. It is exported through the widget API for a package's own animation tick.

No other caller changes. Every other nextRender caller was checked: those reached from inside a pass are coalescing paint and placement (repaint, page geometry, target paint, the legend, margin layout and projection, the FAB, the TOC) and run correctly in the same pass; the rest are asked for from input or observer callbacks, whose timing is unchanged.

Measured on triage-board with design mode on, narrowing the window: the settled reading holds two frames after the resize against three on main, in all 20 paired trials.

This replaces the planned move of target and legend boxes to CSS anchor positioning, which Chrome 154 can't carry: an anchored box isn't clipped by its target's scroll container, an anchor inside a widget's shadow root is invisible to chrome outside it, and a display: contents element is no anchor at all.

Checks: npm run test:runtime, the everyday suite, and the complete nightly suite (3150 passed) on the branch before the merge of main.

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

🤖 Generated with Claude Code

max-sixty and others added 2 commits September 24, 2026 21:52
rendering.js now owns the one animation frame Leaf asks for. nextRender
queues into it, and work a callback queues runs in the same pass, before
the frame paints: a repaint that moves the page and the target boxes,
design legend and action bar that follow it land in one frame instead of
one frame apart. A chain that keeps asking finishes on the next frame
after eight generations. The pass waits a microtask step between
callbacks, as the browser does between its own, and reports a callback's
error without stopping the owners after it.

nextFrame is the call for a step that must not run in the pass that
asked for it; the scroll glide, the place-hold follow loop and the
interaction gallery's frame pause move onto it, since each re-asks from
inside its own callback.

Measured on triage-board with design mode on, narrowing the window: the
settled reading holds two frames after the resize against three on main,
in every one of 20 paired trials.

Behavior that moved: tests/runtime/rendering.test.mjs's "work a callback
queues for the next update" now asserts the opposite for nextRender and
holds nextFrame to the old timing.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit ad75041 into main Sep 25, 2026
5 checks passed
@max-sixty
max-sixty deleted the one-render-loop branch September 25, 2026 05:15
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