Repository navigation
:has() is treated as zero specificity, so the minifier can wrap a list in :is() and raise specificity #1410
mattcosta7
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
:has()is treated as zero specificity when Lightning CSS decides whether a selector list can be wrapped in:is(). Per Selectors 4,:has()takes the specificity of its most specific argument. Because of the mismatch, the minifier can wrap a list it believes has equal specificities, which raises the specificity of the less specific selectors.In
selectors/builder.rs(specificity),Component::Has(..)is grouped withComponent::Where(..)under "Does not affect specificity".Reproduction (lightningcss 1.33.0)
Output:
Lightning CSS sees
.a:has(.x):hoveras (0,2,0) and.b:modalas (0,2,0), so it wraps them. Per spec the first is (0,3,0), so.b:modalgoes from (0,2,0) to (0,3,0) and can now beat rules it used to lose to.Expected: either compute
:has()specificity as the max of its arguments (then the specificities differ and the selectors are split into separate rules), or don't wrap.Related
:is()when a target lacks:has(), which changes the specificity of every other selector in the list #1324 covers the same wrapping behavior triggered by a target lacking:has(). This report is about:has()specificity itself, which decides whether the wrap is safe.:is()wrapper is often the rightmost compound, and Blink/WebKit can't index a rule by a multi-argument:is(), so the rule is matched against every element. That is a performance consequence rather than a bug. We detect it in a lint rule and compare it against Lightning CSS output.I searched issues and discussions for
:hasand specificity and found nothing on this. Happy to open it as an issue if that's preferred.All reactions