Skip to content

Commit 0d0ea39

Browse files
authored
Fix stale CSS emit by invalidating all modules (#1066)
1 parent cb28d4d commit 0d0ea39

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

.changeset/fluffy-knives-dress.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 stale emitted CSS in SSR mode by invalidating all modules related to a file

packages/vite-plugin/src/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,18 @@ export function vanillaExtractPlugin({
216216
cssMap.get(absoluteId) !== source
217217
) {
218218
const { moduleGraph } = server;
219-
const [module] = Array.from(
219+
const modules = Array.from(
220220
moduleGraph.getModulesByFile(absoluteId) || [],
221221
);
222222

223-
if (module) {
224-
moduleGraph.invalidateModule(module);
223+
for (const module of modules) {
224+
if (module) {
225+
moduleGraph.invalidateModule(module);
225226

226-
// Vite uses this timestamp to add `?t=` query string automatically for HMR.
227-
module.lastHMRTimestamp =
228-
(module as any).lastInvalidationTimestamp || Date.now();
227+
// Vite uses this timestamp to add `?t=` query string automatically for HMR.
228+
module.lastHMRTimestamp =
229+
(module as any).lastInvalidationTimestamp || Date.now();
230+
}
229231
}
230232

231233
server.ws.send({

0 commit comments

Comments
 (0)