Repository navigation
Reserve an inline patch's drawn height by counting it at first paint - #3984
Merged
Merged
Conversation
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]>
…unt, quiet the advice
leaf-agent
previously approved these changes
Oct 25, 2026
leaf-agent
approved these changes
Oct 25, 2026
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]>
This was referenced Oct 25, 2026
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_
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.
An
lf-diffwith 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 nodata-heightfor 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 authoreddata-heightis no longer needed (several in the examples were stale:pr-key-hunkstated 521 and drew 492).How it sizes itself. A new
x-initialrenderer (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 topackages/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-trackinreading.css. The renderer draws nothing and loads no Lit. Asourcediff, aview="file"diff and a patch with a hunkless file get no counts and behave as before, and an authoreddata-heightstill 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
overflowis set) moves intopackages/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.mjschecks them against$languages.paths. The column geometry the renderer uses (two 1 px frame borders, a gutter ofdigits + 3ch, 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_atholds 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 --renderno longer tells the author to setdata-heighton 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 computedblock-sizeother thanauto, read throughcomputedStyleMap().unreservedHeightsthen advises only where the first paint left the height to the content, or wheredata-lf-heightset it. When a counted diff misses its height, the defect is the widget's, and the package author'skeeps-first-boxcheck reports it. Adata-heightwould go stale with the next edit. The rule names no tag.test_the_render_gate_reports_a_compact_spill_and_unreserved_heightsgains a case where a widget's own theme sized its box, and that case gets no advice.Pages and instructions.
data-heightis removed from every inline-patchlf-diffinexamples/and from the registryx-examples.docs/has none. The source-boundpr-exact-patchkeeps itsdata-height(2108 corrected to 1697), andpr-reviewed-requestgoes from 959 to 1037, both from the render check's advice.page-layout.md, thelf-diffx-instructionsand the diff author guide now say an inline patch reserves its own height and only asourcediff takesdata-height. The diff package'skeeps-first-boxentry intests/known_widget_findings.pyis gone, sinceleaf package check --render packages/diffnow reports nothing.Known limits. The prose wrap counts every character as one column, so tabs and wide characters (CJK) in a
.mdor.txtrow 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-diagramstill takes an authoreddata-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 touchedlf-diffbrowser 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 oftest_bundled_widgets_meet_the_widget_quality_checks, andpage check --renderonworktree-diffs,pr-walkthroughanddiff-thread-gallery. The only findings left areunpointableadvice on markup this change doesn't touch.Closes #3174