Skip to content

Commit f227cfc

Browse files
ccjmnedummdidumm
andauthored
fix: Allow global-like pseudo-selectors refinement (#15313)
For instance, specifying a tree-structural pseudo-class to `::view-transition-new` should still constitute a valid global-like selector. Fixes #15312 --------- Co-authored-by: Simon H <[email protected]>
1 parent e74fbcb commit f227cfc

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

.changeset/gold-hairs-jog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: allow global-like pseudo-selectors refinement

packages/svelte/src/compiler/phases/2-analyze/css/css-analyze.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ const css_visitors = {
133133

134134
node.metadata.is_global = node.selectors.length >= 1 && is_global(node);
135135

136-
if (node.selectors.length === 1) {
136+
if (
137+
node.selectors.length >= 1 &&
138+
node.selectors.every(
139+
(selector) =>
140+
selector.type === 'PseudoClassSelector' || selector.type === 'PseudoElementSelector'
141+
)
142+
) {
137143
const first = node.selectors[0];
138144
node.metadata.is_global_like ||=
139145
(first.type === 'PseudoClassSelector' && first.name === 'host') ||

packages/svelte/tests/css/samples/view-transition/expected.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88
::view-transition-old {
99
animation-duration: 0.5s;
1010
}
11+
::view-transition-old:only-child {
12+
animation-duration: 0.5s;
13+
}
1114
::view-transition-new {
1215
animation-duration: 0.5s;
1316
}
17+
::view-transition-new:only-child {
18+
animation-duration: 0.5s;
19+
}
1420
::view-transition-image-pair {
1521
animation-duration: 0.5s;
1622
}

packages/svelte/tests/css/samples/view-transition/input.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88
::view-transition-old {
99
animation-duration: 0.5s;
1010
}
11+
::view-transition-old:only-child {
12+
animation-duration: 0.5s;
13+
}
1114
::view-transition-new {
1215
animation-duration: 0.5s;
1316
}
17+
::view-transition-new:only-child {
18+
animation-duration: 0.5s;
19+
}
1420
::view-transition-image-pair {
1521
animation-duration: 0.5s;
1622
}

0 commit comments

Comments
 (0)