Skip to content

fix(compiler-sfc): replace trailing universal selector with :where([id]) in scoped styles #13404

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
wants to merge 1 commit into from
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
8 changes: 4 additions & 4 deletions packages/compiler-sfc/__tests__/compileStyle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ describe('SFC style preprocessors', () => {
}"
`)
expect(compileScoped(`.foo * { color: red; }`)).toMatchInlineSnapshot(`
".foo[data-v-test] [data-v-test] { color: red;
".foo[data-v-test] :where([data-v-test]) { color: red;
}"
`)
expect(compileScoped(`.foo :active { color: red; }`))
Expand All @@ -503,7 +503,7 @@ describe('SFC style preprocessors', () => {
`)
expect(compileScoped(`.foo *:active { color: red; }`))
.toMatchInlineSnapshot(`
".foo[data-v-test] [data-v-test]:active { color: red;
".foo[data-v-test] :where([data-v-test]):active { color: red;
}"
`)
expect(compileScoped(`.foo * .bar { color: red; }`)).toMatchInlineSnapshot(`
Expand All @@ -512,12 +512,12 @@ describe('SFC style preprocessors', () => {
`)
expect(compileScoped(`:last-child * { color: red; }`))
.toMatchInlineSnapshot(`
"[data-v-test]:last-child [data-v-test] { color: red;
"[data-v-test]:last-child :where([data-v-test]) { color: red;
}"
`)
expect(compileScoped(`:last-child *:active { color: red; }`))
.toMatchInlineSnapshot(`
"[data-v-test]:last-child [data-v-test]:active { color: red;
"[data-v-test]:last-child :where([data-v-test]):active { color: red;
}"
`)
})
Expand Down
19 changes: 12 additions & 7 deletions packages/compiler-sfc/src/style/pluginScoped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ function rewriteSelector(
}
}
// store the universal selector so it can be rewritten later
// .foo * -> .foo[xxxxxxx] [xxxxxxx]
// .foo * -> .foo[xxxxxxx] :where([xxxxxxx])
starNode = n
}

Expand Down Expand Up @@ -280,15 +280,20 @@ function rewriteSelector(
}),
)
// Used for trailing universal selectors (#12906)
// `.foo * {}` -> `.foo[xxxxxxx] [xxxxxxx] {}`
// `.foo * {}` -> `.foo[xxxxxxx] :where([xxxxxxx]) {}`
if (starNode) {
selector.insertBefore(
starNode,
selectorParser.attribute({
attribute: idToAdd,
value: idToAdd,
raws: {},
quoteMark: `"`,
selectorParser.pseudo({
value: ':where',
nodes: [
selectorParser.attribute({
attribute: idToAdd,
value: idToAdd,
raws: {},
quoteMark: `"`,
}),
],
}),
)
selector.removeChild(starNode)
Expand Down