Skip to content

Commit 73b55f8

Browse files
author
Ben Jervis
authored
Fix vite plugin (#327)
1 parent f9e1a67 commit 73b55f8

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

.changeset/pretty-pants-shave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vanilla-extract/vite-plugin': patch
3+
---
4+
5+
Fix bug where precompiled .css.ts files (.css.js) were treated differently in SSR mode.

packages/vite-plugin/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ export function vanillaExtractPlugin({ identifiers }: Options = {}): Plugin {
5858
return null;
5959
}
6060

61-
if (ssr && code.indexOf('@vanilla-extract/css/fileScope') === -1) {
61+
if (ssr) {
62+
// If file already has a scope (has already run through babel plugin)
63+
if (code.indexOf('@vanilla-extract/css/fileScope') > -1) {
64+
return code;
65+
}
66+
6267
const filePath = normalizePath(path.relative(packageInfo.dirname, id));
6368

6469
const packageName = packageInfo.name
@@ -68,7 +73,6 @@ export function vanillaExtractPlugin({ identifiers }: Options = {}): Plugin {
6873
return `
6974
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
7075
setFileScope("${filePath}", ${packageName});
71-
7276
${code}
7377
endFileScope();
7478
`;

0 commit comments

Comments
 (0)