Skip to content

Commit f4bd196

Browse files
authored
vite: Don't watch files or invalidate VE modules during SSR (#1617)
1 parent 7d1c4d8 commit f4bd196

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

.changeset/weak-boats-walk.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@vanilla-extract/vite-plugin': patch
3+
---
4+
5+
Don't watch files or invalidate VE modules during SSR
6+
7+
Fixes a bug where a dependent of a Vanilla Extract module could be evaulated multiple times during `ssrLoadModule`, potentially causing bugs with singleton variables such as React context.

packages/vite-plugin/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export function vanillaExtractPlugin({
183183
closeWatcher() {
184184
return compiler?.close();
185185
},
186-
async transform(code, id) {
186+
async transform(code, id, options = {}) {
187187
const [validId] = id.split('?');
188188

189189
if (!cssFileFilter.test(validId)) {
@@ -214,8 +214,8 @@ export function vanillaExtractPlugin({
214214
map: { mappings: '' },
215215
};
216216

217-
// We don't need to watch files in build mode
218-
if (isBuild) {
217+
// We don't need to watch files or invalidate modules in build mode or during SSR
218+
if (isBuild || options.ssr) {
219219
return result;
220220
}
221221

0 commit comments

Comments
 (0)