Skip to content

Commit 31ce350

Browse files
committed
Only use :is() if all selectors have the same specificity
1 parent 5c105fb commit 31ce350

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9499,6 +9499,27 @@ mod tests {
94999499
..Browsers::default()
95009500
},
95019501
);
9502+
9503+
prefix_test(
9504+
r#"
9505+
.foo.foo:hover, .bar:focus-visible {
9506+
color: red;
9507+
}
9508+
"#,
9509+
indoc! {r#"
9510+
.foo.foo:hover {
9511+
color: red;
9512+
}
9513+
9514+
.bar:focus-visible {
9515+
color: red;
9516+
}
9517+
"#},
9518+
Browsers {
9519+
safari: Some(14 << 16),
9520+
..Browsers::default()
9521+
},
9522+
);
95029523
}
95039524

95049525
#[test]

src/rules/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ use custom_media::CustomMediaRule;
8383
use document::MozDocumentRule;
8484
use font_face::FontFaceRule;
8585
use import::ImportRule;
86+
use itertools::Itertools;
8687
use keyframes::KeyframesRule;
8788
use media::MediaRule;
8889
use namespace::NamespaceRule;
@@ -593,8 +594,11 @@ impl<'i, T: Clone> CssRuleList<'i, T> {
593594
let incompatible = if style.selectors.0.len() > 1 && !style.is_compatible(*context.targets) {
594595
// The :is() selector accepts a forgiving selector list, so use that if possible.
595596
// Note that :is() does not allow pseudo elements, so we need to check for that.
597+
// In addition, :is() takes the highest specificity of its arguments, so if the selectors
598+
// have different weights, we need to split them into separate rules as well.
596599
if context.targets.is_compatible(crate::compat::Feature::IsSelector)
597600
&& !style.selectors.0.iter().any(|selector| selector.has_pseudo_element())
601+
&& style.selectors.0.iter().map(|selector| selector.specificity()).all_equal()
598602
{
599603
style.selectors =
600604
SelectorList::new(smallvec![

0 commit comments

Comments
 (0)