Skip to content

Commit bf4a828

Browse files
committed
fix(vite): exclude virtual modules from vitest fs module cache
Vitest 5.0.4 enables fsModuleCache by default, which kept serving stale #nitro/virtual/* modules after handler rescans in watch mode.
1 parent 580ac82 commit bf4a828

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎src/build/vite/vitest.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export function nitroVitest(ctx: NitroPluginContext): VitePlugin {
5050
if (!setupFiles.includes(setupPath)) {
5151
setupFiles.push(setupPath);
5252
}
53+
// Virtual modules change on handler rescans without a file change, so the fs module cache
54+
// (keyed in memory by id until a file is invalidated) would keep serving stale code
55+
context.defineCacheKeyGenerator?.(({ id }) =>
56+
id.startsWith("#nitro/virtual/") ? false : undefined
57+
);
5358
setupVitestWatch(ctx, context);
5459
},
5560

0 commit comments

Comments
 (0)