You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Selector lists with ::part() or ::slotted() are wrapped in :is(), so the rule matches nothing
#1417
When a selector list contains a selector the targets don't support, the minifier wraps the list in :is(). It skips the wrapping when a selector has a pseudo-element, because :is() doesn't accept pseudo-elements. That check only reads the HAS_PSEUDO flag, but ::part() and ::slotted() set their own flags (HAS_PART, HAS_SLOTTED), so lists with them are still wrapped.
A fix with tests is ready on aronwoost:fix-is-part-slotted (compare). Pull requests are limited to collaborators, so feel free to open a PR from that branch.
Reproduction (lightningcss 1.33.0)
With minify: true and Firefox 104 in the targets (no :has() support),
.a:has(.b)::part(foo),.c:has(.b)::part(foo){color: red }
:is() takes a forgiving selector list, so browsers drop both selectors and the rule matches nothing, in every browser. There is no warning. ::slotted() behaves the same, and so do other unsupported selectors, for example a:hover::part(foo), a:focus-visible::part(foo) with Safari 14 in the targets. We hit this in production, where a rule for small screens was silently lost.
Fix
The check in src/rules/mod.rs now also reads is_part() and is_slotted(), so these lists are split into one rule per selector, as lists with ::before already are:
New cases in test_merge_rules cover ::part() with :focus-visible and with :has(), and ::slotted() with :has(). cargo test --all-features, yarn test and yarn tsc pass.
Only lists that used to come out wrapped in :is() change, and those matched nothing before.
Related
:is is being incorrectly used for ::part selectors #515 reported the same output through nesting. Its fix added compat data for ::part, so a list of only ::part selectors is no longer treated as unsupported, but this check stayed as it was.
becomes .b::part(w){border:0;display:flex} with the fix: .b::part(w) gets display: flex, which it didn't before, but .a:has(.x)::part(w) is dropped. The fix doesn't change that.
AI assistance and human review
AI was used to prepare these changes. Human-reviewed by @aronwoost.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
When a selector list contains a selector the targets don't support, the minifier wraps the list in
:is(). It skips the wrapping when a selector has a pseudo-element, because:is()doesn't accept pseudo-elements. That check only reads theHAS_PSEUDOflag, but::part()and::slotted()set their own flags (HAS_PART,HAS_SLOTTED), so lists with them are still wrapped.A fix with tests is ready on
aronwoost:fix-is-part-slotted(compare). Pull requests are limited to collaborators, so feel free to open a PR from that branch.Reproduction (lightningcss 1.33.0)
With
minify: trueand Firefox 104 in the targets (no:has()support),becomes
:is()takes a forgiving selector list, so browsers drop both selectors and the rule matches nothing, in every browser. There is no warning.::slotted()behaves the same, and so do other unsupported selectors, for examplea:hover::part(foo), a:focus-visible::part(foo)with Safari 14 in the targets. We hit this in production, where a rule for small screens was silently lost.Fix
The check in
src/rules/mod.rsnow also readsis_part()andis_slotted(), so these lists are split into one rule per selector, as lists with::beforealready are:New cases in
test_merge_rulescover::part()with:focus-visibleand with:has(), and::slotted()with:has().cargo test --all-features,yarn testandyarn tscpass.Only lists that used to come out wrapped in
:is()change, and those matched nothing before.Related
:is is being incorrectly used for ::part selectors #515 reported the same output through nesting. Its fix added compat data for
::part, so a list of only::partselectors is no longer treated as unsupported, but this check stayed as it was.Minifier wraps a selector list in
:is()when a target lacks:has(), which changes the specificity of every other selector in the list #1324 and :has() is treated as zero specificity, so the minifier can wrap a list in :is() and raise specificity #1410 are about the same wrapping, when:has()is counted as zero specificity. Here the specificities really are equal, so fixing those doesn't cover this.Nesting has the same gap:
.el::part(x) { .parent & { … } }compiles to.parent :is(.el::part(x)). fix: avoid wrapping pseudo-element selectors in :is() during nesting compilation #1156 (for Ligthning generate :is with pseudo element #352) addshas_pseudo_element()to the nesting check, which covers::before/::afterbut, from reading the diff, not::part()/::slotted().Splitting can still lose a selector when another selector in the list repeats an earlier rule (Incompatible selectors can be dropped after rule merging when targets require selector splitting #1260, Minifier silently drops a rule when a selector list is split and another selector in that list duplicates an earlier rule #1310). With Firefox 104 targets,
becomes
.b::part(w){border:0;display:flex}with the fix:.b::part(w)getsdisplay: flex, which it didn't before, but.a:has(.x)::part(w)is dropped. The fix doesn't change that.AI assistance and human review
AI was used to prepare these changes. Human-reviewed by @aronwoost.
All reactions