Repository navigation
Option to split instead of wrapping unsupported selector lists in :is(), which loses rule indexing #1411
mattcosta7
started this conversation in
Ideas
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.
When a selector list contains a selector that a target doesn't support, Lightning CSS keeps the list valid by wrapping it in
:is()if all specificities are equal (otherwise it splits the rule). The wrapped selector then has an:is()with several arguments as its rightmost compound.Reproduction (lightningcss 1.33.0)
Output:
Why this matters
Browser engines (Blink, WebKit) bucket style rules by the rightmost compound selector, using an id, class, tag or attribute. A multi-argument
:is()has no such key, so the rule goes into the universal bucket and is checked against every element on each style recalc. I'm going from how the engines are documented to work and haven't benchmarked the cost here.In a large codebase this adds up. We found about 50 CSS Modules that compiled to this shape, mostly through
:global(...)lists and nesting under a list parent, which Lightning CSS also treats as unsupported. Splitting the rule by hand avoids it. We now enforce that with a lint rule and check its predictions against Lightning CSS output.Idea
The wrapping is a size optimization that keeps list semantics, and splitting costs bytes. Would an opt-in make sense? For example an option to split instead of wrap, or to split only when the wrapped selector would be the rightmost compound, which is the case where indexing is lost.
Related
:is()when a target lacks:has(), which changes the specificity of every other selector in the list #1324: the same wrapping behavior, where it changes specificity.:has()is treated as zero specificity, so the wrap can raise specificity.All reactions