Skip to content

Commit b23d267

Browse files
authored
[fix] improper :global() style encapsulation (#6560)
1 parent ab825ed commit b23d267

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/compiler/compile/css/Selector.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,12 @@ function block_might_apply_to_node(block: Block, node: Element): BlockAppliesToN
278278
return BlockAppliesToNode.NotPossible;
279279
}
280280

281-
if (selector.type === 'PseudoClassSelector' || selector.type === 'PseudoElementSelector') {
282-
continue;
281+
if (block.selectors.length === 1 && selector.type === 'PseudoClassSelector' && name === 'global') {
282+
return BlockAppliesToNode.NotPossible;
283283
}
284284

285-
if (selector.type === 'PseudoClassSelector' && name === 'global') {
286-
// TODO shouldn't see this here... maybe we should enforce that :global(...)
287-
// cannot be sandwiched between non-global selectors?
288-
return BlockAppliesToNode.NotPossible;
285+
if (selector.type === 'PseudoClassSelector' || selector.type === 'PseudoElementSelector') {
286+
continue;
289287
}
290288

291289
if (selector.type === 'ClassSelector') {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
warnings: []
3+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
div>div.svelte-xyz{color:red}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<style>
2+
:global(div) > div {
3+
color: red;
4+
}
5+
</style>
6+
7+
<div>
8+
<div />
9+
</div>

0 commit comments

Comments
 (0)