From 851b258c346fdddd4467a12f41189b7855df8c43 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 442ece308dbaff..37381d5ea7c8a5 100644 --- a/packages/vite/src/node/server/moduleGraph.ts +++ b/packages/vite/src/node/server/moduleGraph.ts @@ -229,8 +229,10 @@ export class ModuleGraph { // 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,