Skip to content

Commit a8f7fc4

Browse files
committed
fix: :root Selector should not be scoped (vuejs#85)
1 parent f7bfc16 commit a8f7fc4

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/stylePlugins/scoped.ts

+9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ export default postcss.plugin('add-id', (options: any) => (root: Root) => {
4646
if (n.type !== 'pseudo' && n.type !== 'combinator') {
4747
node = n
4848
}
49+
50+
if (
51+
n.type === 'pseudo' &&
52+
n.value === ':root' &&
53+
n === selector.last
54+
) {
55+
n.value += ' '
56+
node = n
57+
}
4958
})
5059

5160
if (node) {

test/stylePluginScoped.spec.ts

+13
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,16 @@ test('spaces before pseudo element', () => {
135135
expect(code).toContain('.abc[test],')
136136
expect(code).toContain('[test]::selection {')
137137
})
138+
139+
test('scoped :root selector', () => {
140+
const { code } = compileStyle({
141+
source: `:root { --color: red; }
142+
:root p { --color: blue; }
143+
`,
144+
filename: 'test.css',
145+
id: 'test'
146+
})
147+
148+
expect(code).toContain(':root [test] { --color: red;')
149+
expect(code).toContain(':root p[test] { --color: blue;')
150+
})

0 commit comments

Comments
 (0)