Skip to content

feat(css): style() ranges and cq units weren't worked out - #109

Merged
jamesconwaydev merged 1 commit into
mainfrom
css-container-rest
Nov 19, 2026
Merged

jamesconwaydev merged 1 commit into
mainfrom
css-container-rest

Conversation

@jamesconwaydev

@jamesconwaydev jamesconwaydev commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

#99 left three parts of container queries out of the cascade (#100):

  • style() read a range like style(--gap > 1em) as unknown, so it never held.
  • cqw, cqh, cqi, cqb, cqmin and cqmax always used the viewport, even when there was a container around them.
  • Nothing crossed into shadow trees.

Change

All of it is in crates/parsec-css. There are no new dependencies.

  • Ranges in style(), CSS Conditional 5 §6.2. You can compare two values or three, and three must all point the same way. Each value can be a custom property's name or any value with var() in it. A value is substituted from the container's custom properties, typed as a number, percentage, length, angle, time, frequency or resolution, and computed on the container, so em is the container's. If a value can't be typed, or two values have different types, the range is false, not unknown. A unitless zero counts as a length when compared with one. A ; in a style() feature now makes the feature unknown, as WPT expects.

  • Container query units, at computed-value time. Each element keeps the width and height of its nearest size container on each axis. With no container, it keeps the small viewport's (the environment's). inline-size containment follows the container's own writing mode, and cqi and cqb follow the element's. Inside a @container prelude, the units are the container's own. If container_sizes gives no size for a container, the units look past it to the next one out. It costs a few hash lookups per element.

  • Size queries: calc() that mixes px with em or rem is now computed against the container. vw and the other viewport units now use the viewport, not the container.

  • API: ContainerQuery::evaluate takes a media::QueryLengths (font size, viewport, container units, writing mode) and a callback for range values, in place of the bare font size. Feature::evaluate_with is the media feature evaluator with those lengths.

  • Shadow DOM: not done, so this is only part of Container queries: style() ranges, container query units, shadow DOM #100. The 27 shadow-tree cases build their trees with declarative shadow roots (<template shadowrootmode>). crates/parsec's tree builder doesn't attach those: a <template> always gets an ordinary contents fragment, and the DOM has no shadow root node. That's a core change, Netweir first. The core would need:

    • a shadow root node kind and a host-to-root link;
    • the HTML Standard's "in head" template start-tag steps that attach a declarative shadow root, with an option to allow them, which the fragment parser leaves off;
    • slot assignment, so the flat tree is available;
    • selector support for :host, :host(), :host-context() and ::slotted().

    After that, the cascade needs per-tree sheets, flat-tree inheritance and container lookup, and tree-scoped container names.

Tests

  • WPT cascade and at-rules: 1,198 of 1,345, up from 1,141. 57 cases leave known-failures.txt:

    • 27 from at-container-style-parsing.html;
    • 12 from query-evaluation-style.html;
    • 12 from container-units-in-at-container.html;
    • 6 calc() size queries.

    None started failing. Still failing in Container queries: style() ranges, container query units, shadow DOM #100's scope:

    • 27 shadow DOM cases, for the reason above;
    • 13 cases with pseudo-elements as containers or styled inside one: Styler doesn't style pseudo-elements;
    • 6 container query units inside @keyframes, sampled part-way through an animation: there are no animations;
    • 2 in container-units-auto.html, whose container is width: auto, so the runner can't size it without layout.
  • Media queries (1,370 of 1,370), computed values and CSS parsing are unchanged.

  • New unit tests:

    • cq* units through nested size and inline-size containers, and the viewport fallback;
    • style ranges with custom properties and em, and a type mismatch giving false;
    • the range parser's accepted and refused shapes;
    • unitless zero against a length.
  • Fuzzing: the target now evaluates container queries with a range-value callback and with none, and its page has a vertical size container. It ran clean for 5 minutes: 113,816 inputs.

Cascade bench. cargo run --release --manifest-path bench/Cargo.toml -- css, all 13 pages, median of 5 on an M2 Max. Runs were interleaved, and each started with the one-minute load under 2.8:

Run Before (main) After Change
1 2,382.9 ms 2,392.5 ms +0.4%
2 2,378.0 ms 2,427.1 ms +2.1%

Most of run 2's difference is whatwg-full, and the load rose to 3.6 during that run. I read both as within noise.

cargo fmt --all, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace and cargo deny check pass.

Part of #100

Range syntax in style() queries was read as unknown, so
style(--gap > 1em) never held. Each value is now substituted from the
container's custom properties, typed as a number or dimension and
computed on the container, then compared; a value that isn't one, or
two of different types, makes the range false (CSS Conditional 5
6.2). A stray ; in a style() feature makes it unknown.

The cq* units fell back to the viewport everywhere. Each element now
carries the width and height its nearest size containers give on each
axis, inline-size containment following the container's writing mode,
with the small viewport when there's none; cqi and cqb follow the
element's own writing mode. In a @container prelude they're the
container's own.

Size queries also compute calc() with em and rem against the
container, and vw against the viewport instead of the container.
ContainerQuery::evaluate takes a QueryLengths and a callback for range
values in place of the font size.

WPT cascade and at-rules: 1,198 of 1,345 pass, from 1,141.
@jamesconwaydev
jamesconwaydev merged commit fa277e5 into main Nov 19, 2026
33 checks passed
@jamesconwaydev
jamesconwaydev deleted the css-container-rest branch November 19, 2026 15:02
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.

1 participant