From 9bd71e498a9cf1ec1b377b1c186f715101a63649 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 21 Jan 2025 13:36:37 +0000 Subject: [PATCH] fix(vite): add back `invalidateModule` call this reverts commit b765251ce866a82ab8bf217416b249c724e20609 --- packages/vite/src/vite.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/vite.ts b/packages/vite/src/vite.ts index 3b5ed399f6..7e200c1a42 100644 --- a/packages/vite/src/vite.ts +++ b/packages/vite/src/vite.ts @@ -213,12 +213,13 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => { nuxt.hook('vite:serverCreated', (server: vite.ViteDevServer, env) => { // Invalidate virtual modules when templates are re-generated - ctx.nuxt.hook('app:templatesGenerated', (_app, changedTemplates) => { - for (const template of changedTemplates) { + ctx.nuxt.hook('app:templatesGenerated', async (_app, changedTemplates) => { + await Promise.all(changedTemplates.map(async (template) => { for (const mod of server.moduleGraph.getModulesByFile(`virtual:nuxt:${encodeURIComponent(template.dst)}`) || []) { - server.reloadModule(mod) + server.moduleGraph.invalidateModule(mod) + await server.reloadModule(mod) } - } + })) }) if (nuxt.options.vite.warmupEntry !== false) {