Skip to content

Hold lf-shot's drawn size from first paint, so the page below doesn't jump - #6142

Merged
max-sixty merged 3 commits into
mainfrom
shot-reserve
Nov 16, 2026
Merged

max-sixty merged 3 commits into
mainfrom
shot-reserve

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

lf-shot now holds its drawn size from first paint, so the content below no longer jumps when the shot's module draws. Leaf doesn't hide the page before presentation; it only turns transitions off. So the empty shot painted first and grew once its module drew. On a test page, the paragraph under an 1800×746 shot moved from y 207 to y 565. It was out of place for about 90 ms in Chromium (about 400 ms on a cold load) and about 450 ms in Firefox, and the render check recorded a layout shift of CLS 0.179.

Before the module defines the element, lf-shot:not(:defined)::before takes the drawn shot's size. That size is:

  • the toolbar row, plus the label row where the shot is narrow;
  • the stage's padding and gutter;
  • a frame sized from data-lf-media-width and data-lf-media-height, which delivery already writes, using typed attr().

The frame follows the drawing's limits: never larger than the captures, no wider than the stage, no taller than the screen. The screen height is one registered property, --lf-shot-screen: 100svh, read by both the placeholder and fit(), so the two agree. The placeholder applies only on screen, only while the runtime runs (html[data-lf-interactive]), and only when both media attributes are present.

What to weigh:

  • Typed attr() arrives in Chrome 133, Firefox 155 and Safari 27.3, which is still in beta. Current Safari keeps only the toolbar and padding, so it still jumps by the image height.
  • The CSS repeats fitShotGeometry's sizing rules. The widget-quality check, which now has no accepted lf-shot resize, fails if they drift apart at desktop width or in a workspace pane, but it doesn't check narrow widths.
  • On a page that scrolls sideways under a classic scrollbar, a shot capped at the screen's height is now up to the scrollbar's thickness taller than the visible window, because fit() reads the same 100svh the placeholder does.
  • The gutter under real classic scrollbars is untested: this Mac's engines use overlay scrollbars.
  • The widget-quality case for the default package currently fails on main, on lf-note (keeps-first-box, from Draw code notes as cards under the key they explain, and let the reader hide them from the block's toolbar #6109), not on lf-shot.

Max asked for this after #6127 traced most of the render check's startup shifts to lf-shot. Codex reviewed it and found three cases where the held box differed from the drawn one: the screen-height cap under a horizontal scrollbar, a shot with no media size, and printing during startup. Each is fixed and measured equal.

Tests: held and drawn heights agree in Chromium, Firefox and WebKit, at four window sizes, at phone width, in dark, and for five shot shapes. Stills show no change inside the drawn shot. A new screenshot-startup stills state holds the runtime. The four test_render_commands shot tests, shot-view.test.mjs and pnpm run check:browser pass.

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

…ays put

An lf-shot had no box until its module drew it, then grew to its drawn height,
moving everything below it on a page already painted. On a page with a shot under
its first paragraph (1440x900, a 1800x746 pair), the paragraph painted at y 207
and jumped to 565 when the module drew: 90 ms after first paint in Chromium and
450 ms in Firefox, on a warm reload, before the page presented.

Until lf-shot is defined, its ::before now takes the box the first drawing takes:
the toolbar (the view chooser's row, `--lf-chooser`, in its padding, and the label
row in a narrow shot), then the stage's padding, gutter and the frame's 1px border
around the captures at Slider's fitted size. The size comes from the
`data-lf-media-width` and `data-lf-media-height` delivery already paints, read with
typed attr(): the stage's width at the captures' ratio, never past their own
height, nor taller than the screen below the toolbar, as `fitShotGeometry` fits
them. That makes package-themes.md's account of those attributes true. The hold
is scoped to html[data-lf-interactive], so a page whose runtime won't start holds
no room, and a browser without typed attr() holds the toolbar and padding only.

The held box matched the drawn one to 0.1 px in Chromium, Firefox and WebKit, at
1440x900, 900x600, 500x800 and 390x844 (touch and mouse), for wide, mixed-height,
tall, small and strip captures. The widget-quality check now finds no
keeps-first-box change for lf-shot, so its accepted finding goes, and that check
fails if the hold drifts from the drawing. A `screenshot-startup` stills state
shows release-notes' shot with its runtime held.
…en and with a size

Three cases where the room an lf-shot holds before its module draws differed from
what it then drew:

- The screen bound. The held frame stopped at `100svh`, while the module's fit stopped
  at `documentElement.clientHeight`, which leaves out a classic horizontal scrollbar.
  On a page that scrolls sideways under one, a tall shot held 900 px and drew 884, and
  everything below it moved up 16 px. The screen's height is now the stylesheet's
  alone: `--lf-shot-screen: 100svh`, registered as a `<length>` so that it computes to
  pixels, which the held frame reads through `var()` and the fit through
  `getComputedStyle`. The two read one computed value, so they agree in every engine,
  scrollbars or not. A shot that the screen bounds, on a page scrolling sideways under
  a classic scrollbar, now stands up to that bar's thickness taller than the visible
  window, as the held frame already did.
- A shot whose images have no size delivery can read held 68 px, its toolbar and
  padding, and drew nothing there. It now holds nothing until it draws.
- Print during startup kept the held room as blank space, 357 px for a 1800x746 pair;
  the hold is now for the screen only.

Measured on base and head: the tall shot under classic scrollbars in Chromium (900
held, 884 drawn, now 900 and 900); the sizeless shot (68 held, now 0) and print
emulation (357, 900 and 68 px held, now 0) in Chromium, Firefox and WebKit; and,
unchanged, every shape at 1440x900, 900x600 and phone width.
@max-sixty
max-sixty merged commit 3f0e19f into main Nov 16, 2026
5 checks passed
@max-sixty
max-sixty deleted the shot-reserve branch November 16, 2026 08:45
leaf-agent added a commit that referenced this pull request Nov 16, 2026
… size (#6191)

Three default-package widgets drew a different box once presented than
at first paint, so the content below them moved during startup.
`test_bundled_widgets_meet_the_widget_quality_checks[default]` failed on
all five findings in #6181. It fails on main `f1b367375` and passes on
this branch, as do the other 19 tests in
`tests/journeys/test_widget_quality.py`.

- **`lf-note` (from #6109).** A docked note's left padding included its
line's indent. The module copies that indent only when it docks the
note, so a card sized to its words grew by indent × ch (333→365px for
the example's 4-space line). The indent is now the note's
`margin-inline-start`, and `max-inline-size` subtracts it. The words,
card, caret and right edge stand where #6109 put them, and the box keeps
its first-paint size.
- **`lf-code`'s registry example (from #6157).** HTML drops a newline
right after `<pre>` but not after a `<code>` inside it. The example's
`<code class="language-python">` was followed by a newline, which
painted a blank first row (about 20px) that the module then strips. The
example now starts its code on the `<code>` line.
- **`lf-shot` (from #6142).** The placeholder frame (`::before`) had the
stage's `scrollbar-gutter`. A box's `width` includes its own gutter, so
`aspect-ratio` sized the frame from a width 2 × the gutter wider than
the frame the module fits. On hosts with classic scrollbars (Linux,
Windows) it held 2G/ratio too much: 18.75px for the example, where G is
one 15px gutter. #6142 was measured on overlay scrollbars, where G is 0.
The gutter now sits on the empty `lf-shot` itself, so the frame inside
it takes the stage's content width. Chromium, Firefox and WebKit all
give `aspect-ratio` that width-including-gutter behaviour (probed in the
Playwright engines).

**What the reviewer should weigh**

- On classic-scrollbar hosts, the gutter on the empty shot narrows its
`lf-shot` container by 2G. A shot whose width is within 30px above the
450px narrow-toolbar breakpoint therefore holds the narrow toolbar's
height before upgrade. Before this change, every shot on those hosts was
off by 2G/ratio. On overlay-scrollbar hosts nothing changes.
- The authoring hazard behind the `lf-code` finding is wider than the
example. #6157 wrote `<pre><code class="language-…">` followed by a
newline in about 14 places in `examples/` and `docs/how-it-works.html`,
and the `lf-code` instruction doesn't warn about the newline
(`lf-text-document`'s does). Those pages still paint one blank row
before upgrade. Fixing them, and adding the sentence to the instruction
(which would need an instruction score), is left out of this repair.

**Drawn states** (`leaf-dev stills`, base `f1b367375` vs head):
`code-comparison`, `code-reader-feedback` and `screenshot-comparison`
are pixel-identical. `walkthrough-code` changes only in text
anti-aliasing: the note crops match, and the indent now lands as a
fractional margin rather than padding. `screenshot-startup`, the held
placeholder, now reserves about 12px less, the gutter error for its
1800×746 shot:

| before | after |
|---|---|
|
![before](https://github.com/user-attachments/assets/f1ec9003-6087-4d91-83b5-74373ee281ab)
|
![after](https://github.com/user-attachments/assets/bf8117bd-61cc-434b-b1be-f40b19645f15)
|

Focused checks: the `note`/`shot`/`annot` tests in
`test_code_and_documents.py` and both `test_render_commands.py` files
(19 passed), and `pnpm run check:browser`.

Closes #6181 — automated triage

Co-authored-by: leaf-agent <[email protected]>
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