From a03bb0e2ba35af314c57fc98600bb76566592239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Fri, 4 Oct 2024 21:54:00 +0900 Subject: [PATCH] fix(hmr): don't try to rewrite imports for direct CSS soft invalidation (#18252) --- packages/vite/src/node/server/moduleGraph.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/moduleGraph.ts b/packages/vite/src/node/server/moduleGraph.ts index e932285bd91d93..c1329630313b6d 100644 --- a/packages/vite/src/node/server/moduleGraph.ts +++ b/packages/vite/src/node/server/moduleGraph.ts @@ -215,8 +215,10 @@ export class EnvironmentModuleGraph { // to only update the import timestamps. If it's not statically imported, e.g. watched/glob file, // we can only soft invalidate if the current module was also soft-invalidated. A soft-invalidation // doesn't need to trigger a re-load and re-transform of the importer. + // But we exclude direct CSS files as those cannot be soft invalidated. const shouldSoftInvalidateImporter = - importer.staticImportedUrls?.has(mod.url) || softInvalidate + (importer.staticImportedUrls?.has(mod.url) || softInvalidate) && + importer.type !== 'css' this.invalidateModule( importer, seen,