Skip to content

Draw a chart's first frame outside the ResizeObserver delivery that measured its room - #6155

Merged
max-sixty merged 3 commits into
mainfrom
chart-first-draw-outside-delivery
Nov 16, 2026
Merged

max-sixty merged 3 commits into
mainfrom
chart-first-draw-outside-delivery

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

A chart drew its first frame inside its own ResizeObserver delivery whenever Plot had already loaded by the time the browser delivered the chart's room, an order a CPU-starved machine makes likely because rendering updates come late while the import finishes. The first frame replaces the chart's children and adds lf-rendered, which lets go of the box the theme held at the stated height, all inside the delivery that reported the chart's room. On a starved run Chrome then ended the round with "ResizeObserver loop completed with undelivered notifications", which failed test_a_chart_keeps_its_stated_height_beside_a_taller_one at teardown and would fail page check --render on a loaded machine. Users saw nothing.

The room delivery now hands the first frame to Leaf's next rendering pass through frameFor, as lf-diagram and lf-shot do, and the legend watch settles paint() in that pass too. Every write draw() makes after an await then lands in a rendering pass or in Plot's load, so the hop #5743 added at the end of draw() goes. Redraws still run inside the delivery so labels fit the new width in the same paint: they write only inside the drawing, whose height is fixed.

What to weigh: this is the third fix of this class in draw(), after #5743 and #6015, and the first to move the deferral to the two places that resolve inside a delivery, so a write added after an await needs no hop of its own. A chart whose room arrives after Plot has loaded draws one frame later, while the theme still holds its box.

Max asked for this fix after a CPU-starved run exposed it. A subagent reviewed it and found only comment inaccuracies, now fixed.

Tests: the test now holds the chart module until the page has loaded Plot, which gives every run the starved order: it fails 3 of 3 on main with the loop error and passes 3 of 3 here. Under taskpolicy -b with 18 busy loops the original test failed 4 of 4 runs on main and passed 5 of 5 on this branch. The chart tests covering legends, redraws, refusals, hidden charts and paper layout pass, as do heat-loss's render gate, pnpm run check and pnpm run test:runtime.

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

…easured its room

A chart drew its first frame inside its own ResizeObserver delivery whenever Plot had already loaded by the time the browser delivered the chart's room, an order a CPU-starved machine makes likely. The first frame adds `lf-rendered`, so the theme stops holding the box at its stated height, and a grid row that stretches its cells grows it inside the delivery that reported it. The browser then ends the round with "ResizeObserver loop completed with undelivered notifications", which failed `test_a_chart_keeps_its_stated_height_beside_a_taller_one` at teardown and would fail `page check --render` on a loaded machine.

The room delivery now hands the first frame to Leaf's next rendering pass through `frameFor`, as `lf-diagram` and `lf-shot` do, and the legend watch settles `paint()` in that pass too. Every write `draw()` makes after an await then lands in a rendering pass or in Plot's load, so the hop #5743 added at the end of `draw()` goes. Redraws still run inside the delivery, so labels fit the new width in the same paint: they write only inside the drawing, whose height is fixed. A chart whose room arrives after Plot has loaded now draws one frame later, while the theme still holds its box.

> _This was written by Claude Code on behalf of max-sixty_
nextRender hands its callback the frame's timestamp, which a promise's resolver would take as its value; the type check refused it.

> _This was written by Claude Code on behalf of max-sixty_
leaf-agent
leaf-agent previously approved these changes Nov 16, 2026
…r it

The test now gives every run the order a CPU-starved machine gave it: the chart module waits until the page has loaded Plot, so the charts' first room delivery comes after the bundle is in. On main that fails every run with the ResizeObserver loop at teardown (3 of 3), and it passes with the fix (3 of 3), where before it failed only under starvation.

> _This was written by Claude Code on behalf of max-sixty_
@max-sixty
max-sixty merged commit a7b1079 into main Nov 16, 2026
5 checks passed
@max-sixty
max-sixty deleted the chart-first-draw-outside-delivery branch November 16, 2026 09:56
max-sixty added a commit that referenced this pull request Nov 16, 2026
…ved Firefox (#6197)

Max's direction for tests whose result depends on CPU: design them so it
can't, confirm that in the nightly runs, and keep starved runs out of
the merge pipeline. This makes the macOS nightly that run: it now uses
four workers on the runner's three cores, which starves every test. A
trial at four workers ([run
43780587059](https://github.com/max-sixty/leaf/actions/runs/43780587059))
took 4h11m against 4h12m at two, with the CPU at 0% idle throughout and
memory peaking at 7.1 of 7.5 GB, no swap. `tests/AGENTS.md` now names
that job as the slow-machine rule's check.

In a starved Firefox, PageUp in a live log can do nothing: Firefox
applies the key's scroll 280–800 ms late, after the reader's 80 ms wait
for it, and no event says the browser won't scroll, so ending the loss
needs a deadline. Max accepted it as a corner case, so the Firefox cases
of `test_a_page_up_in_a_log_a_stream_feeds_leaves_its_end` whose scroll
the browser applies (PageUp, PageUp on a link, wheel, wheel across) are
now non-strict expected failures; this PR's first CI run lost a wheel
the same way. They pass at normal load, as they did locally here and on
main's last three push runs. `u`, which Leaf's own glide scrolls, stays
a plain case.

To weigh: the trial run at four workers had 30 failures against 21 at
two. #6154, #6155, #6166 and #6169 fixed the load-dependent ones found
then, but the first nightly after this may still turn up more; each is a
test whose result depends on speed.

> _This was written by Claude Code on behalf of max-sixty_
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