Bug reportNov 18, 2026· 0:27· 11 views
Vue SFC scoped CSS: :global(A) B compiles to just A — descendant selector is dropped
0:27 total
Comments · 0
Be the first to comment.
Bug reportby SceneRecap AI
medium@vue/compiler-sfc scoped style rewriting (the PostCSS scoped plugin), specifically :global() pseudo handling when :global() is followed by more compound or descendant selectors.
os: macOSapp: Vue SFC Playgrounddpr: 1ssr: OFFmode: DEVlocale: en-USbrowser: Chromium 151.0.7922.34autosave: ONviewport: 1280x720vue_version: @148fdactypescript_version: 6.0.3
Repro steps
- 1.Open Vue SFC Playground. The default Hello World App.vue is shown.
- 2.Click the SFC editor.
- 3.Press Cmd+a to select all code.
- 4.Press Cmd+v to paste a component with <h1>Test heading</h1>, <p>This paragraph should not be affected.</p> and <style scoped> containing :global(body) h1 { background-color: purple; }.
- 5.Observe the PREVIEW pane.
- 6.Click the css tab to view the compiled CSS.
- 7.Click the preview tab to return to the preview.
Expected
The selector :global(body) h1 inside <style scoped> should compile to a selector that targets h1 elements inside body, for example body h1 or a scoped equivalent. Only the h1 'Test heading' should get a purple background. The paragraph and the rest of the page should keep the default background.
Actual
The compiled CSS is body { background-color: purple; }. The descendant h1 part of the selector is missing. The whole preview body turns purple, including the paragraph that should not be affected.
Evidence
visualAfter the paste, the editor shows <style scoped> with :global(body) h1 { background-color: purple; }. The entire preview background is purple, not only the h1.
visualNo code changes. The preview body stays fully purple and the paragraph 'This paragraph should not be affected.' sits on the purple background.
visualThe CSS output tab shows the compiled CSS as body { background-color: purple; }. The h1 descendant selector is dropped.
visualBack on the PREVIEW tab, the paragraph is still on a purple background. This matches the compiled body selector, not the intended body h1.
consoleLanguage service warning from the typescript-semantic plugin: 'Debug Failure. False expression: Script kind should match provided ScriptKind:3 and sourceFile.scriptKind: 1'. This comes from the editor language service, not the CSS compiler, and is likely unrelated.
Issue markdown (copy-paste ready)
## Summary
In a `<style scoped>` block, the selector `:global(body) h1` compiles to `body`. The descendant `h1` part is dropped, so the rule applies to the whole body.
## Environment
- Vue SFC Playground, Vue `@148fdac`, TypeScript 6.0.3, DEV, SSR OFF
- Chromium 151.0.7922.34 on macOS, viewport 1280x720
## Reproduction
1. Open the Vue SFC Playground (0s).
2. Click the SFC editor, press Cmd+a, then Cmd+v (2.8s to 3.7s) with this App.vue:
```vue
<template>
<h1>Test heading</h1>
<p>This paragraph should not be affected.</p>
</template>
<style scoped>
:global(body) h1 {
background-color: purple;
}
</style>
```
3. Look at the PREVIEW pane (5.0s).
4. Open the CSS tab (13.0s).
## Expected
The rule targets `h1` inside `body`, for example `body h1`. Only the heading gets a purple background.
## Actual
Compiled CSS (CSS tab, 15.0s):
```css
body {
background-color: purple;
}
```
The whole preview body is purple, including the paragraph (5.0s, and again at 23.0s after returning to PREVIEW).
## Evidence
- 5.0s: preview background fully purple right after the paste.
- 15.0s: CSS output shows only the `body` selector. `h1` is missing.
- 23.0s: paragraph still on a purple background.
- 4.0s: console warning from the `typescript-semantic` language service ('Script kind should match provided ScriptKind'). This looks unrelated to the CSS output.
## Suspected area
`@vue/compiler-sfc` scoped CSS rewriting: handling of `:global()` when other selectors follow it.
*Recorded with SceneRecap.*Your recordings could explain themselves too.
Free plan · silent recordings welcome · bug reports included.
Try SceneRecap free →