Skip to content

Commit 91eb2a6

Browse files
authored
fix: revert avoid css leaking into emitted javascript (#3402) (#3630)
1 parent 8b4075d commit 91eb2a6

File tree

5 files changed

+2
-18
lines changed

5 files changed

+2
-18
lines changed

packages/playground/css/__tests__/css.spec.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,12 @@ test('linked css', async () => {
3030
})
3131

3232
test('css import from js', async () => {
33-
const importedNoVars = await page.$('.imported-no-vars')
3433
const imported = await page.$('.imported')
3534
const atImport = await page.$('.imported-at-import')
3635

37-
expect(await getColor(importedNoVars)).toBe('magenta')
3836
expect(await getColor(imported)).toBe('green')
3937
expect(await getColor(atImport)).toBe('purple')
4038

41-
editFile('imported-without-variable.css', (code) =>
42-
code.replace('color: magenta', 'color: cyan')
43-
)
44-
await untilUpdated(() => getColor(importedNoVars), 'cyan')
45-
4639
editFile('imported.css', (code) => code.replace('color: green', 'color: red'))
4740
await untilUpdated(() => getColor(imported), 'red')
4841

packages/playground/css/imported-without-variable.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/playground/css/index.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ <h1>CSS</h1>
66
<p class="linked">&lt;link&gt;: This should be blue</p>
77
<p class="linked-at-import">@import in &lt;link&gt;: This should be red</p>
88

9-
<p class="imported-no-vars">
10-
import from js, no vars: This should be magenta
11-
</p>
12-
139
<p class="imported">import from js: This should be green</p>
1410
<p class="imported-at-import">
1511
@import in import from js: This should be purple

packages/playground/css/main.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import './imported-without-variable.css'
2-
31
import css from './imported.css'
42
text('.imported-css', css)
53

packages/vite/src/node/plugins/css.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
263263
} else {
264264
// server only
265265
if (ssr) {
266-
return modulesCode || `export default ''`
266+
return modulesCode || `export default ${JSON.stringify(css)}`
267267
}
268268
return [
269269
`import { updateStyle, removeStyle } from ${JSON.stringify(
@@ -285,7 +285,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
285285
styles.set(id, css)
286286

287287
return {
288-
code: modulesCode || `export default ''`,
288+
code: modulesCode || `export default ${JSON.stringify(css)}`,
289289
map: { mappings: '' },
290290
// avoid the css module from being tree-shaken so that we can retrieve
291291
// it in renderChunk()

0 commit comments

Comments
 (0)