Skip to content

fix(compiler-sfc): scoped style leak when using pseudo classes (fix #8868) #9693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions packages/compiler-sfc/__tests__/compileStyle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,46 @@ describe('SFC scoped CSS', () => {
)
})

test('pseudo class', () => {
expect(compileScoped(`.foo:after { color: red; }`)).toMatch(
`.foo[data-v-test]:after { color: red;`,
)
test.each([
{
message: 'pseudo class with class',
source: `.foo:after { color: red; }`,
expected: `.foo:after[data-v-test] { color: red;`,
},
{
message: 'bare pseudo class at root',
source: `:after { color: red; }`,
expected: `:after[data-v-test] { color: red;`,
},
{
message: 'bare pseudo class as descendent',
source: `div :required { color: red; }`,
expected: `div :required[data-v-test] { color: red;`,
},
{
message: 'pseudo class with tag as descendent',
source: `div input:required { color: red; }`,
expected: `div input:required[data-v-test] { color: red;`,
},
{
message: ':not pseudo class',
source: `input:not(.error) { color: red; }`,
expected: `input:not(.error)[data-v-test] { color: red;`,
},
])('$message', ({ source, expected }) => {
expect(compileScoped(source)).toMatch(expected)
})

test('pseudo element', () => {
expect(compileScoped(`::selection { display: none; }`)).toMatch(
'[data-v-test]::selection {',
'::selection[data-v-test] {',
)
})

test('spaces before pseudo element', () => {
const code = compileScoped(`.abc, ::selection { color: red; }`)
expect(code).toMatch('.abc[data-v-test],')
expect(code).toMatch('[data-v-test]::selection {')
expect(code).toMatch('::selection[data-v-test] {')
})

test('::v-deep', () => {
Expand Down
5 changes: 1 addition & 4 deletions packages/compiler-sfc/src/style/pluginScoped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,7 @@ function rewriteSelector(
}
}

if (
(n.type !== 'pseudo' && n.type !== 'combinator') ||
(n.type === 'pseudo' && (n.value === ':is' || n.value === ':where'))
) {
if (n.type !== 'combinator') {
node = n
}
})
Expand Down