Repository navigation
Show examples before runtime startup - #130
Conversation
leaf-agent
left a comment
There was a problem hiding this comment.
One finding, on the half of the presentation gate that lives in the runtime rather than in the theme.
skills/leaf/assets/runtime/shadow.js builds SHADOW_PRESENTATION_CSS and prepends it to the rules adopted into every declared shadow root; it is keyed on :host-context(body:not([data-lf-presented])) * and sets visibility: hidden !important; opacity: 0 !important. Its own comment names it as the shadow-side twin of the theme's document gate — "the document's main gate cannot hide a dialog promoted out of an x-shadow widget … put the same subtree boundary inside it" — so it is the second half of exactly the rule this PR exempts with html:not([data-lf-eager]). The exemption did not reach it, so on a published example the twin still holds while main around it is readable.
x-shadow is declared by one tag, lf-diff (skills/leaf/packages/default/registry.json), and pr-walkthrough is the one published example that uses it. On the built site that page paints its prose immediately, and the diff — a 957px block, the largest thing on the page — is hidden from the moment the widget attaches its shadow root until presentPage stamps data-lf-presented. Measured against the module's own site/hosted fixtures over the local host: shadow root at 513ms, data-lf-presented at 581ms, so ~68ms of a blank hole mid-document, widening with the seed round-trips that are precisely what the eager path exists to stop the reader waiting on. Holding the two seed responses freezes that state for inspection, and the region renders as an empty column the height of the viewport.
So for a page holding an x-shadow widget, the new sentence in skills/leaf/CLAUDE.md — that an eager document "remains ordinary readable HTML while its illustrative session, widgets, and controls progressively arrive" — isn't the sequence: the widget's authored content is present and upgraded, then blanked by the runtime's own rule, then shown. The new browser regression exercises design-decision, which carries no shadow widget, so it cannot see this; pr-walkthrough is what would.
:host-context() takes a compound selector, so html:not([data-lf-eager]) body:not([data-lf-presented]) won't express it in place — the marker has to be reachable from inside the shadow tree, either as an attribute the body also wears or by omitting SHADOW_PRESENTATION_CSS from the adopted sheet when the root is eager. Which of those is right looks like your call rather than mine; happy to push a commit if you'd like one.
Minor, unrelated: the comment above window.EventSource in docs/session.js still says "No error is ever dispatched, there being no server to lose", and the sessionReady rejection arm added ten lines below dispatches one.
How the window was measured
Both probes ran against tests/test_site.py's own site and hosted fixtures on this merged tree, with uv run pytest -n0, then were deleted.
Held state — routes on **/data.json and **/comments.jsonl collected without continuing, so sessionReady never settles and presentPage never runs:
{'presented': False, 'eager': True, 'h1Visibility': 'visible',
'hostVisibility': 'visible', 'hostRect': 957.25,
'kid': 'DETAILS.', 'kidVisibility': 'hidden', 'kidOpacity': '0'}
kid is the first non-<style> element inside lf-diff's shadow root with text. The host keeps its box, so the layout is right and the content is not painted.
Unheld timing — a MutationObserver installed in an init script, recording performance.now() when lf-diff first has a shadowRoot and when body first has data-lf-presented:
MARKS pr-walkthrough {'shadow': 512.8, 'presented': 580.6}
Negative control on the change itself: reverting the four html:not([data-lf-eager]) selectors in skills/leaf/assets/theme.css to their base form makes test_an_example_paints_while_every_stage_of_site_startup_is_held fail with h1 hidden behind "Applying current decisions…", so the new test does gate what it claims.
ci was green on this head (lint, test) before this review.
leaf-agent
left a comment
There was a problem hiding this comment.
The shadow half of the gate is closed — stageShadow now omits SHADOW_PRESENTATION_CSS when the root wears data-lf-eager, and the regression moved onto pr-walkthrough so #limits-diff's shadow content is asserted visible with both seeds still held. That is the whole of the previous finding, and the theme's lf-shadow:start…lf-shadow:end slice carries no presentation rules of its own, so nothing else re-imposes it inside a declared root.
One thing left, on the invariant doc rather than the code. skills/leaf/CLAUDE.md now reads "The authored main stays inert behind the presentation gate … A live page also hides it", which states a two-tier gate — inert for every page, hidden only for a live one. theme.css has no such tier: visibility: hidden, opacity: 0, interactivity: inert, and pointer-events: none are one declaration block behind a single html:not([data-lf-eager]):has(script[type="module"][src="/leaf.js"]) body:not([data-lf-presented]) > main selector (interactivity: inert !important appears exactly once in the file, inside it), so the eager marker drops all four together. This PR's own test says the same from the other side: expect(page.locator("body > main")).to_have_css("pointer-events", "auto") on the published example.
That matters more than wording, because interactivity before replay is the one genuinely new reader-facing behaviour here, and this paragraph is where a later session goes to find out what an eager document permits. As written it answers "inert until presented", which is the opposite. The suggestion states the gate as one thing the marker lifts whole.
docs/example-previews.json records a digest of every checked-in file that can change a captured standalone page. Five merges after fff16e6 edited those inputs without rerunning scripts/example-previews.py, and #130's own regeneration was taken on a branch cut at ac5ba54, so it landed stale too. Reran scripts/example-previews.py on af4eb72.
Published examples currently inherit Leaf’s live-page presentation gate, so opening one from the home page can show the loading surface until the static session and runtime finish starting.
This stamps only built showcase pages as eager HTML, keeps normal live pages behind atomic replay, and overlaps the showcase’s seed reads with runtime and widget loading. Eager shadow-DOM widgets omit their matching replay gate as well, so a progressively upgraded diff cannot turn into a blank region while the session finishes.
The staged browser regression holds each startup boundary on the shadow-widget example and asserts the authored document and upgraded diff remain visible without relying on elapsed time. Generated gallery previews were refreshed from their owning script.
Verified with
uv run pytest tests/test_site.py,uv run pytest tests, and the changed-file pre-commit hooks.