Skip to content

diff: compare the cascade layer order the sheets declare - #295

Open
samoht wants to merge 2 commits into
mainfrom
diff-layer-order-walk
Open

diff: compare the cascade layer order the sheets declare#295
samoht wants to merge 2 commits into
mainfrom
diff-layer-order-walk

Conversation

@samoht

@samoht samoht commented Aug 2, 2026

Copy link
Copy Markdown
Owner

The tree walk paired two @layer blocks, found their bodies equal and reported nothing — even when the two sheets declare the layers in opposite orders and so resolve a conflict between them the opposite way.

@layer a; ahead of a @layer b block makes a the weaker layer. Drop that one statement and b becomes weaker instead: the same rules now win differently. The walk read the two sheets as identical.

It now compares the declared layer order and names the pairs that swapped:

Cascade layer order changed:
├─ b now precedes a
└─ order: a, b -> b, a

The order comes from Resolve.layered_rules, the model that already backs cascade_layer_precedence_rank — exposed as Resolve.layer_order rather than written a second time. Layers only one sheet declares are left to the existing added/removed reporting, so the comparison is over the layers both sides have. A layer declared inside @media/@supports/@container is not part of it, matching what Resolve.layer_order counts; that boundary is documented in both mlis.

Tests: the case that was pinned as a known gap is now a positive assertion, alongside a nested-sublayer case and a control — @layer a;@layer b; against @layer a,b; is one order in two spellings and stays quiet.

Tree_diff.t gains a layer_order field and Css_compare.stats a layer_order_swaps count, so a layer-order-only diff reads Changes: 1 swapped layer pair instead of falling through to "none classified structurally".

samoht added 2 commits August 3, 2026 21:22
The walk pairs two @layer blocks on their bodies and never reads the
order the sheet declares, so dropping a leading `@layer a;` pin - which
swaps which of the two layers wins - reads as no difference at all.
A layer's strength comes from where its name is first declared, not from
where its rules stand, so two sheets holding the same @layer blocks with
the same bodies can resolve a conflict the opposite way. The walk reads
the order through Resolve.layer_order, the one the cascade resolves
against, and names the layer pairs that swapped.
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