Skip to content

Commit 4332072

Browse files
Philipp Rudloffkleinfreund
authored andcommitted
fix(compiler-sfc): scoped style leak when using pseudo classes
Fix a scoped style leak when using pseudo classes caused by the scoped style attribute (i.e. `[data-v-...]`) not being attached to the key part of a selector when it contains pseudo class selectors. Closes #8868.
1 parent f70f7ca commit 4332072

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

packages/compiler-sfc/__tests__/compileStyle.spec.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,46 @@ describe('SFC scoped CSS', () => {
4747
)
4848
})
4949

50-
test('pseudo class', () => {
51-
expect(compileScoped(`.foo:after { color: red; }`)).toMatch(
52-
`.foo[data-v-test]:after { color: red;`,
53-
)
50+
test.each([
51+
{
52+
message: 'pseudo class with class',
53+
source: `.foo:after { color: red; }`,
54+
expected: `.foo:after[data-v-test] { color: red;`,
55+
},
56+
{
57+
message: 'bare pseudo class at root',
58+
source: `:after { color: red; }`,
59+
expected: `:after[data-v-test] { color: red;`,
60+
},
61+
{
62+
message: 'bare pseudo class as descendent',
63+
source: `div :required { color: red; }`,
64+
expected: `div :required[data-v-test] { color: red;`,
65+
},
66+
{
67+
message: 'pseudo class with tag as descendent',
68+
source: `div input:required { color: red; }`,
69+
expected: `div input:required[data-v-test] { color: red;`,
70+
},
71+
{
72+
message: ':not pseudo class',
73+
source: `input:not(.error) { color: red; }`,
74+
expected: `input:not(.error)[data-v-test] { color: red;`,
75+
}
76+
])('$message', ({ source, expected }) => {
77+
expect(compileScoped(source)).toMatch(expected)
5478
})
5579

5680
test('pseudo element', () => {
5781
expect(compileScoped(`::selection { display: none; }`)).toMatch(
58-
'[data-v-test]::selection {',
82+
'::selection[data-v-test] {',
5983
)
6084
})
6185

6286
test('spaces before pseudo element', () => {
6387
const code = compileScoped(`.abc, ::selection { color: red; }`)
6488
expect(code).toMatch('.abc[data-v-test],')
65-
expect(code).toMatch('[data-v-test]::selection {')
89+
expect(code).toMatch('::selection[data-v-test] {')
6690
})
6791

6892
test('::v-deep', () => {

packages/compiler-sfc/src/style/pluginScoped.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,7 @@ function rewriteSelector(
170170
}
171171
}
172172

173-
if (
174-
(n.type !== 'pseudo' && n.type !== 'combinator') ||
175-
(n.type === 'pseudo' && (n.value === ':is' || n.value === ':where'))
176-
) {
173+
if (n.type !== 'combinator') {
177174
node = n
178175
}
179176
})

0 commit comments

Comments
 (0)