Skip to content

Reserve an inline patch's drawn height by counting it at first paint - #3984

Merged
max-sixty merged 6 commits into
mainfrom
fix/3174-diff-height-count
Oct 25, 2026
Merged

max-sixty merged 6 commits into
mainfrom
fix/3174-diff-height-count

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

An lf-diff with its patch inline now first paints at the height its drawing lands at, so nothing below it moves when it upgrades, and the author writes no data-height for it. Before, its first paint was the raw patch's height: on a demo page the drawing moved what followed by up to +213 px at 420 px wide and +252 px on a 390 px phone. With this change the shift is 0 px at 420, 700 and 1280 px and on the phone, in Chrome and in Firefox, and an authored data-height is no longer needed (several in the examples were stale: pr-key-hunk stated 521 and drew 492).

How it sizes itself. A new x-initial renderer (packages/diff/initial/lf-diff.js) runs as each diff's markup arrives. It counts what the drawing is made of: the files, whether they open, and the rows from the first @@ on, less a separator for a first hunk that starts its file. For prose files, which wrap, it adds the greedy wrap of each row at the column the drawing will give it. It writes the counts as custom properties on the host, and the package theme turns them into the reserved height using the drawing's own sizing tokens. Those tokens move to packages/diff/styles/geometry.css, which the document theme and the shadow tree both import, and the text scroller's 15 px track becomes --lf-text-scroll-track in reading.css. The renderer draws nothing and loads no Lit. A source diff, a view="file" diff and a patch with a hunkless file get no counts and behave as before, and an authored data-height still wins.

What it costs, and why it can't wait. The renderer is inlined into every page that has an lf-diff: 3.4 KB, 1.36 KB gzipped. The prototype measured about 5 ms of main-thread time before first paint; I didn't re-measure it on this head. The work can't move later because the height has to be in place before the first paint, and no module has loaded by then.

One wrap rule. The choice of which files wrap (Markdown and plain text, unless overflow is set) moves into packages/diff/widgets/overflow.js, and both the widget and the initial renderer import it. The classic script can't read the registry, so the rule names the Markdown extensions itself; tests/runtime/diff-overflow.test.mjs checks them against $languages.paths. The column geometry the renderer uses (two 1 px frame borders, a gutter of digits + 3 ch, 2 ch before the text and 8 px after it) stays as numbers in the script. test_an_inline_patch_first_paints_at_the_height_it_draws_at holds those numbers to the drawing: it compares first-paint and drawn heights at 1280 px and on a 390 px phone, with code, wrapped prose and folded diffs. It caught a gutter that was off by one column. It can't catch an error smaller than one character width.

Render-check advice. page check --render no longer tells the author to set data-height on a box whose own theme already reserved a height from its markup. firstBoxes (render-checks/driver.js) records whether a stylesheet gave each first-paint box a height of its own: a computed block-size other than auto, read through computedStyleMap(). unreservedHeights then advises only where the first paint left the height to the content, or where data-lf-height set it. When a counted diff misses its height, the defect is the widget's, and the package author's keeps-first-box check reports it. A data-height would go stale with the next edit. The rule names no tag. test_the_render_gate_reports_a_compact_spill_and_unreserved_heights gains a case where a widget's own theme sized its box, and that case gets no advice.

Pages and instructions. data-height is removed from every inline-patch lf-diff in examples/ and from the registry x-examples. docs/ has none. The source-bound pr-exact-patch keeps its data-height (2108 corrected to 1697), and pr-reviewed-request goes from 959 to 1037, both from the render check's advice. page-layout.md, the lf-diff x-instructions and the diff author guide now say an inline patch reserves its own height and only a source diff takes data-height. The diff package's keeps-first-box entry in tests/known_widget_findings.py is gone, since leaf package check --render packages/diff now reports nothing.

Known limits. The prose wrap counts every character as one column, so tabs and wide characters (CJK) in a .md or .txt row get too few rows. The width is read once, when the diff's markup arrives. That doesn't matter on a served page, whose root always shows its scrollbar (html[data-lf-live]), but an export on a platform with classic scrollbars can lose a column when its scrollbar appears. The prototype's survey found Firefox one row over for heavily wrapped prose at 420 px. No diff that is counted lacks the file comment press, so the touch over-reserve I was asked to check (9 px per file) doesn't happen: on a 390 px phone the reserved height matches the drawn one exactly. Diagrams are not covered: lf-diagram still takes an authored data-height.

#3951 also touched lf-diff rows. It merged before this branch's last merge from main, and this head was measured with it in.

Checks run: pnpm run test:runtime, pnpm run check, the touched lf-diff browser tests and the render-gate test (-n0), tests/model/interact_contract/test_vocabulary.py, test_registry_door.py, test_revision_delivery.py, the diff case of test_bundled_widgets_meet_the_widget_quality_checks, and page check --render on worktree-diffs, pr-walkthrough and diff-thread-gallery. The only findings left are unpointable advice on markup this change doesn't touch.

Closes #3174

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

max-sixty and others added 5 commits October 25, 2026 09:20
Prototype for #3174. An inline-patch lf-diff first paints its raw patch, then
its drawing replaces it at a different height and moves what follows. A small
x-initial renderer (initial/lf-diff.js, 3.3 KB unminified) counts what the
drawing stands on — files, rows from the first `@@` on, less a separator for a
first hunk that starts its file, and for prose files the greedy wrap of each row
at the column the drawing gives it — and writes the counts as custom properties
on the host. The package theme turns them into the reserved height from the
drawing's own anatomy tokens: the filter row (`--lf-line`, `--lf-diff-gap`),
each file's name row (`--lf-diff-head-pressed`), the scroll track
(`--lf-text-scroll-track`) and the code line (`--code-line`). It draws nothing
and loads no Lit.

The anatomy tokens move to geometry.css, which theme.css and shadow.css both
import, so the shadow tree and the first paint read one value; the text
scroller's 15px track becomes `--lf-text-scroll-track` in reading.css.

An authored data-height still wins, by cascade layer (lf-layouts over lf-base).
A `source` diff, a whole-file view and a patch with a hunkless file get no
counts and keep today's behavior.

The registry-door test pops x-initial before turning off x-upgrade, since the
initial renderer's own requirement would otherwise answer first.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 25, 2026
@max-sixty
max-sixty merged commit 4f51fe9 into main Oct 25, 2026
4 checks passed
@max-sixty
max-sixty deleted the fix/3174-diff-height-count branch October 25, 2026 17:19
leaf-agent added a commit that referenced this pull request Oct 25, 2026
The fallback-style test required every bundled source widget to share
the generic fallback's overflow. #3984 deliberately gives an inline diff
a clipped first-paint box to reserve its drawn height, so that equality
now rejects the intended layout. Compare the shared typography
independently of package layout; retain the generic fallback's scrolling
and its release after rendering in both document and shadow contexts.

The original case reproduced `clip` versus `auto` on current main. With
this test correction, it passes alongside both desktop and touch cases
of `test_an_inline_patch_first_paints_at_the_height_it_draws_at` (3
passed).

Closes #4095 — automated triage

Co-authored-by: leaf-agent <[email protected]>
leaf-agent added a commit that referenced this pull request Oct 26, 2026
The diff first-paint test added in #3984 closed its browser context
before the shared fixture could collect final page diagnostics. Leave
context teardown with the fixture, preserving the held-request cleanup
and first-paint height assertions.

The fixture ownership check reproduces the reported failure before this
removal and passes afterward. Both wide and touch cases of the inline
patch first-paint test also pass (3 tests total).

Closes #4237 — automated triage

Co-authored-by: leaf-agent <[email protected]>
max-sixty added a commit that referenced this pull request Nov 5, 2026
…it drew (#5571)

`page-layout.md` has said since #3984 that `page check --render`
suggests a drawing's height wherever it differs from what was reserved,
and no check did. A fresh agent writing an eval report gave its
`lf-diagram` no `data-height`. The check printed only startup
layout-shift evidence, whose `after` box was all zeros, so the agent
found the 937px height with `leaf-dev probe`.

The render check now gives `drawn-height` advice for every drawn element
whose tag declares `x-height`. It fires when the drawing is taller or
shorter than the box the element showed before it drew. On that report's
page, copied with the diagram's `data-height` varied:

| `data-height` | Advice |
|---|---|
| none | `<lf-diagram id=campaign-flow> was 314px tall before drawing
and its drawing is 937px tall, so what follows it moved down 623px as it
drew; data-height="937" holds the drawing's height from first paint` |
| 600 | `… was 600px tall before drawing and its drawing is 937px tall,
so what follows it moved down 337px as it drew; …` |
| 1200 | `… was 1200px tall before drawing and its drawing is 937px
tall, leaving 263px blank under the drawing; …` |
| 937 | nothing |

The shift evidence couldn't carry the height. The Layout Instability API
clips each source's box to the window, and that diagram's drawn box sits
below the window inside the workspace's tab scroller, so it came back as
zeros. A shift-based check also can't see a stated height that is too
large, since that moves nothing. So the reading comes from the element's
own box:

- The probe driver records the first box each such element shows before
it is marked `lf-rendered`, with a ResizeObserver started as the page
parses, so nothing holds startup.
- After the page settles, `drawnHeights` measures the drawing with
`data-lf-height` lifted for one synchronous read, since the diagram's
CSS keeps a larger stated height after drawing.
- Elements hidden at check time, or never marked drawn, such as a file
tree held at its stated height, are left out. It is read in the light
scheme at the desktop and phone windows, so a drawing whose height
depends on the width gets a finding at each.

On the shipped examples it fires only on `pr-walkthrough`, and both
firings are real. `pr-key-hunk`, an inline diff, shows its patch as
508px of source text before it draws and is 473px drawn, at both
windows. `lf-pr-brief` states 1037px and draws 1041px on desktop and
1204px on the phone. `security-boundary`, `alert-review`, `heat-loss`
and `live-progress` get nothing.

An inline diff shows its source text until it draws, and #4724 accepted
the resize that follows, so `packages/diff/instructions/author.md` says
to leave `data-height` off inline patches. The advice gives a height
there too. Whether inline patches should take one is a separate
decision.

`page-layout.md` and `evals/README.md` now say what the check reports,
and `page-layout.md` no longer says `lf-diff` sizes a textual patch from
its inline content, which it hasn't since #4724.
`test_a_drawing_reports_its_height_where_its_first_box_differed` covers
no height, too small, too large, a match and an authored body that
already takes the drawing's height. It fails with the reservation lift
removed and with the stated height read in place of the recorded box.
The startup shift, diagram reservation and widget-quality render tests,
the browser type check and `build/registry.test.mjs` pass.

> _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.

Every content edit to an lf-diagram or lf-diff needs a hand-copied data-height and another check run

2 participants