Skip to content

Accept an author's own shadow DOM, report every capture problem at once, and measure ordinary pages against Leaf - #4546

Merged
max-sixty merged 13 commits into
mainfrom
leaf-out-of-the-way
Oct 28, 2026
Merged

max-sixty merged 13 commits into
mainfrom
leaf-out-of-the-way

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Three follow-ups to #4490 under "Primitives, not a template" (SOUL.md): two obstacles lifted for authors writing ordinary pages, and a test that keeps the principle measured.

Behavior that changes

  • An author's own shadow DOM is accepted. The render gate no longer refuses a page whose own custom element attaches a shadow root the registry doesn't declare (undeclared-shadow is gone). The passage reading already treated such a root as opaque, reading its host by its light children as Python does, so no anchoring rule changed: words only the shadow tree shows can't be quoted, a drag inside it captures no passage, and x-shadow stays the way a widget makes its shadow words quotable. page-behavior.md, module-authoring.md and the x-shadow key description say so.
  • One page check reports every capture problem. revision_artifact.py collects findings across the whole capture of index.html and page/ (every file, every import and stylesheet reference) and refuses once with all of them; a save's refusal names the same list. Each refusal's code and text are unchanged. A file that can't be read isn't followed, a refused @import yields nothing further, and a malformed stylesheet reports css-invalid rather than aborting the check. Callers that read one module or sheet still get a raise, now carrying every problem in it.
  • Export no longer fails on a declaration the browser ignores. Omitting an unavailable URL from a rule that also holds an invalid declaration (broken;) raised on serializing it; the invalid declaration is now dropped, as the browser drops it.

A plain-HTML corpus

tests/fixtures/plain/ holds eight standalone pages, each an ordinary pattern (CSS reset, :root palette with dark mode, grid app shell with sticky header, guarded animation and fixed badge, native form and <dialog>, a module fetching a page file, a classic script, and three ports of real designs), whose only Leaf edit is wrapping the body in main. tests/browser/test_plain_pages.py runs page check --render's readings on each, then serves it standalone and through Leaf and compares every property the author's CSS decides, in light and dark, with and without reduced motion. Its module header is the corpus's one description.

Every page still meets an obstacle that needs a maintainer decision, so each runs as an expected failure pinned to its exact findings (kind, property, elements): any new finding fails the page, and so does a pinned one that stops occurring. The obstacles: theme rules beating type and colour a page sets on :root or body, color-scheme: light dark on the root, body as a size container with html painting Leaf's paper, the refusal of classic inline scripts, scrollbar-clearance on a scrolling nav, and past-column on a fixed corner badge. The first three belong to the decided split of the reading look out of the core; the last three are open decisions.

Checks

tests/model (1850), pnpm run test:runtime (685), the render-gate tests the shadow change touches, the new corpus test (4–7 s a case at load ~28), and deliberate overrides showing the corpus catches a new theme override and a dark-only colour change. Codex reviewed the combined branch; its five findings are fixed or answered, and the fixes were re-checked.

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

`page check`, and the save that runs the same capture, used to refuse a
candidate at the first reference it couldn't capture, so an author with
three bad references ran the check three times. The capture now collects
a finding for each problem across every file and reference (a module or
stylesheet outside page/, a bare or escaped import, a symlink out of
page/, an unreadable file, invalid CSS, a refused url() or @import,
non-UTF-8 script or CSS, a script or stylesheet link the page may not
load) and refuses once with all of them, each reported once. Each
refusal's code and words are unchanged.

One collector runs through the capture. The per-file readers keep what
they refuse as data beside the references they accept
(`_javascript_imports`, `_CssReading.refused`), so a file with one bad
import still has its other imports resolved. `javascript_imports`,
`css_dependencies` and `resource_dependencies` take an optional list to
collect into, and without one raise every problem together, as the
layer composition and delivery callers expect. A file that can't be read
isn't followed, and each path is visited once, so a refused file the
document names isn't reported again when the rest of page/ is captured.
`ArtifactError` now carries any number of findings.

Delivery's `rewrite_css` no longer raises on a sheet capture would
refuse. It only rewrites captured sheets and Leaf's own layer.

Test: a page with eight distinct capture problems gets all eight from
one check, and the save's refusal names the same ones.
The render gate no longer refuses a page holding a shadow root the
registry doesn't declare with x-shadow (finding `undeclared-shadow`,
probe `undeclaredShadowRoots`). An author's ordinary custom element with
its own shadow DOM now passes `page check --render`.

The refusal guarded nothing the passage walk doesn't already keep. The
walk enters only declared roots, so an undeclared root is opaque. Its
own words are in neither reading. The browser reads its host by its
light children, slotted or not, as the file reading (passages.py) does,
because the file can't know a script will attach a root. So a quote the
agent writes on those words lands beside the host, and a drag inside the
root raises no passage and comments on the page. The finding's advice,
"declare x-shadow", also couldn't be followed for such an element:
a declared root counts only when it is built through shadowStage.

The walk skipping unslotted light children was considered and left out.
Python would still accept quotes on those words, and the browser would
detach them. Drags across the host would also give quotes the server's
reanchoring can't find.

Behavior changes:
- The gate accepts undeclared shadow roots. The probe-only tests for
  form controls and thread chrome go with the probe.
- A runtime test pins the reading: an undeclared root's words stay out,
  and its host reads by its light children.
- The gate's composed project-widget page gains `author-card` as a
  clean control.
- page-behavior.md and module-authoring.md tell authors that their own
  shadow DOM is fine but opaque to comments, and that x-shadow is for
  shadow words the user should quote. The x-shadow key's description
  says the same.
Adds a corpus of eight standalone pages under tests/fixtures/plain/, each
written as an ordinary web page and showing a pattern the others don't,
whose one Leaf-specific edit is wrapping the body's content in main: a
reset with a palette and dark mode on :root, a grid app shell with a sticky
header, an editorial grid with a sticky masthead, a body-centred instrument
with native range inputs, reduced-motion-guarded animation with a fixed
badge, a form with native inputs and a dialog, a module script that builds
the page from page/ data fetched relative to itself, and a classic inline
script. The three survey seeds are trimmed into the first ones.

tests/browser/test_plain_pages.py asks of each page what `page check
--render` asks (source check, page code, render gate) and then compares the
page served as a static site with the candidate Leaf serves. It reads from
the standalone page, over CDP, which properties the author's CSS decides on
each element (declared there, or inherited from the nearest declaring
ancestor's author rule) and requires those to compute the same in Leaf, in a
light medium with motion and a dark one with reduced motion; it also
compares positioned boxes at rest and scrolled, the canvas around body, an
open dialog, and the root's colour scheme. Theme defaults on properties the
author left alone are not compared. Two controls, a theme rule overriding an
author's h1 letter-spacing and one making main a scroll container, fail the
affected pages.

Every page currently fails on at least one obstacle that needs a decision,
so each is an expected failure naming it (OBSTACLES, KNOWN); any other
finding still fails the page, and an obstacle that stops occurring fails it
until its entry goes:

- theme rules on body, semantic elements and class idioms (.lede, .facts dt)
  outrank type and colour the author set on an ancestor;
- :root declares color-scheme: light dark, opting light-only pages into the
  browser's dark controls and dialogs;
- body's size containment keeps its background off the canvas, which html
  paints with Leaf's --paper;
- page check refuses a classic inline script;
- the render gate refuses a horizontal scroller with less than 15px of
  scrollbar clearance, and a fixed box straddling main's content edge.

The pages stay out of the example corpus, whose sweeps hold Leaf's own pages
to suite rules (write_watch.js flagged the instrument's own script) that an
author's script owes nobody.

> _This was written by Claude Code on behalf of max-sixty_
Two regressions from collecting every capture problem:

- A stylesheet whose parse holds a node tinycss2 can't serialize, such
  as a stray `}`, crashed the check with a TypeError where it used to be
  refused as css-invalid, and lost every other finding. `_read_css` now
  splits only a sheet it refused nothing in. `rewrite_css` refuses a
  sheet the walk refused, as it did before collection, so no refused
  parse reaches serialization.
- A refused `@import` was still walked as a nested block, so
  `@import url("missing.json")` reported css-import and then
  dependency-unreadable, and `@import url(a b)` reported css-invalid and
  then css-import. The import's prelude is now read once. A refusal
  inside it, or of the import itself, ends it, and only an accepted
  import yields its URLs.

Test: the stylesheet boundary test gains a refused url() import, an
import whose URL is invalid, and a stray `}`. Each gets exactly one
finding.
…heme

Review found two ways the plain-page test's expected failures hid new
overrides.

A page listed an obstacle by its kind, so any finding of that kind passed:
an added theme rule `body { font-style: italic !important }` changed 44
elements of the article and went unnoticed under `inherited`. KNOWN now pins
each finding an obstacle explains by kind, property and elements (first
element and count), leaving values out so a theme's colours can change
without churn. Any unpinned finding fails, and so does a pin that stops
occurring; a failure prints each new finding's pin first, ready to file.

Where Leaf's root colour scheme differs from the page's, the test dropped
every dark-only colour difference as following from it, which also hid a
dark-only override of the editorial's own `.kicker` colour. It now reads the
standalone page's dark medium again with the root set to Leaf's scheme and
compares with that, so a difference the browser's system colours explain
disappears and any other stays. Dialogs are closed after their reading so
the reread sees the page at rest.

Checks: the test (8 expected failures), and with both overrides above added
to theme.css, the article and editorial fail naming them.

> _This was written by Claude Code on behalf of max-sixty_
…le URL beside it, instead of failing to serialize it
Re-review of 9118637 found that a pin's first element and count lose
element identity: making the article's blockquote strong normal and its
last paragraph italic kept the same pin, so the new override stayed an
expected failure.

A pin now names the reading, kind and property, and the complete set of
affected elements by a digest, keeping the first element and a count to read
it by; a finding groups by property rather than by value, and its words list
every element with its values. The failure output prints the pin to paste.

Checks: the test (8 expected failures); with that swap added to theme.css,
the article fails on a new font-style pin naming the changed set.

> _This was written by Claude Code on behalf of max-sixty_
@max-sixty
max-sixty merged commit 650215a into main Oct 28, 2026
4 checks passed
@max-sixty
max-sixty deleted the leaf-out-of-the-way branch October 28, 2026 03:39
max-sixty added a commit that referenced this pull request Oct 28, 2026
…room as advice, and let a fixed box cross the column (#4554)

Three more refusals lifted under "Primitives, not a template"
(`SOUL.md`), each decided by the maintainer after the plain-HTML corpus
from #4546 surfaced it.

## Behavior that changes

- **Classic and `async` scripts are accepted.** `page check` refused a
classic script that wasn't `defer src` (`parser-blocking-script`) and
any `async` script (`async-script`), because either could run before the
runtime's module read the page and before it listened for errors.
Delivery now holds every authored script until then instead
(`revision_delivery._deferred`): a classic script gains `defer`, an
inline one by moving its text to a deferred `data:` URL that keeps its
global scope (lines padded and `sourceURL=index.html`, so errors name
their line), and `async` goes. Leaf's own `data-lf-runtime` scripts are
untouched. A page gives up running mid-parse: `document.write` does
nothing, a script sees the whole page, and an inline `onload` can fire
before the function it calls exists; `page-behavior.md` says so. The
runtime is unchanged.
- **A scrollbar collision is advice.** The render gate still names a
horizontally scrolling row with less than 15px below its last line, the
width a macOS overlay scrollbar takes under the pointer, but no longer
refuses the page: the bar covers the row only while the pointer is on
it, the page shows the same outside Leaf, and the room is the author's
call.
- **A fixed box may cross the column's edge.** `past-column` read a
`position: fixed` box overlapping `main`'s edge, such as a badge pinned
to the window's corner, as content spilling into the margin. A fixed box
hangs off the window and can't scroll the page sideways, so it now
answers for itself wherever it stands. One drawn over the prose is still
named by `covered-words`.

The plain-page corpus drops all three obstacles, and its four pages
written as modules only because of the script refusal are plain
`<script>` again.

## Design note

The first implementation of the script change read the authored page
from a second, cached fetch of the delivered document and matched it to
the live DOM, with an early error buffer across the prepaint and layer
client. Deferring at delivery keeps the one rule the refusal stood for
(every page script runs after the runtime has read the page) with about
40 lines in delivery and no runtime change, so it replaced that.

## Checks

`pnpm run check`, `pnpm run test:runtime`, the delivery and document
model tests, the corpus (8 expected failures, every pin matching), and
the render-gate, column and journey tests each change touches. The
script diff test and the early-error test pass with deferral and fail
without it; the fixed-box assertion fails on the old rule. Codex
reviewed both commits; its two findings (a journey still expecting the
fixed-box refusal, and the author guidance understating what deferral
changes) are fixed.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Oct 28, 2026
… delivery uses (#4619)

`page check` now reports everything wrong with a page in one run, and
the CSS it refuses is decided by the same reader delivery uses, so
nothing passes the check and then fails at delivery. Part of the
"Primitives, not a template" survey (`SOUL.md`), after #4490, #4546 and
#4554.

## Behavior that changes

- **Markup errors no longer hide page-file problems.** A page with a
markup error stopped there, so a missing `page/` file or broken
stylesheet surfaced only on the next run. Capture now runs beside markup
validation over one walk of the document, and each problem is reported
once, by the check that owns it (`validation/source.py`,
`revision_artifact._collect`).
- **A broken `page/registry.json` reports one problem per declaration.**
The registry stopped at its first error. It now collects the first
problem in each widget entry and each missing layer fact
(`registry/state.gathering()`), so a registry with several bad entries
takes at most a few runs instead of one per entry. `RegistryError` and
the layer refusals carry a list of findings. A boolean attribute schema
(`true`/`false`) reads as typeless instead of crashing the check.
- **One reader judges CSS syntax.** `revision_artifact._read_css`, the
reader delivery rewrites sheets with, decides `css-syntax` for pages,
messages, templates and declarative shadow roots alike; the walk check
and delivery share (`structure.delivered_elements`/`delivered_sheets`)
means a sheet the check skips is one delivery skips too.
- **A declaration the browser drops is advice on a page.** `css-dropped`
(for example `color: ;` or a stray `broken;`) no longer refuses a page:
the browser ignores the declaration, the page renders the same outside
Leaf, and the author sees the finding. A package's stylesheet still
refuses it, since packages are maintained code (`layer._stylesheet`).
`validation.md` says so.

## Checks

The model tests for authored markup, the layer and registry contracts,
media, vocabulary, document and layer inspection, module delivery and
page inspection (885 passed, after merging current `main`), and `pnpm
run check`. Codex reviewed each commit; its findings (the two CSS
parsers disagreeing, a problem reported twice, the template and
shadow-root walks diverging, a crash on boolean schemas, several missing
layer facts merged into one finding) are fixed here.

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