Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vite: Fix stale CSS emit by invalidating all modules #1066

Merged
merged 2 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fluffy-knives-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vanilla-extract/vite-plugin': patch
---

Fix stale emitted CSS in SSR mode by invalidating all modules related to a file
14 changes: 8 additions & 6 deletions packages/vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,18 @@ export function vanillaExtractPlugin({
cssMap.get(absoluteId) !== source
) {
const { moduleGraph } = server;
const [module] = Array.from(
const modules = Array.from(
moduleGraph.getModulesByFile(absoluteId) || [],
);

if (module) {
moduleGraph.invalidateModule(module);
for (const module of modules) {
if (module) {
moduleGraph.invalidateModule(module);

// Vite uses this timestamp to add `?t=` query string automatically for HMR.
module.lastHMRTimestamp =
(module as any).lastInvalidationTimestamp || Date.now();
// Vite uses this timestamp to add `?t=` query string automatically for HMR.
module.lastHMRTimestamp =
(module as any).lastInvalidationTimestamp || Date.now();
}
}

server.ws.send({
Expand Down