Skip to content

Commit a985d43

Browse files
fix: invalidate Vite module graph on template/style HMR updates
When a template or style file changes, the custom fs.watch callback clears the internal resourceCache and sends an angular:component-update WebSocket event. However, it does not invalidate the corresponding module in Vite's module graph. This causes Vite's transform cache to serve stale compiled output on full page reloads. Add a moduleGraph.invalidateModule() call after the WS event is sent so that Vite re-transforms the component module on the next request.
1 parent 44d2074 commit a985d43

File tree

1 file changed

+7
-0
lines changed
  • napi/angular-compiler/vite-plugin

1 file changed

+7
-0
lines changed

napi/angular-compiler/vite-plugin/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@ export function angular(options: PluginOptions = {}): Plugin[] {
370370
event: 'angular:component-update',
371371
data: eventData,
372372
})
373+
374+
// Invalidate Vite's module transform cache so that a full page reload
375+
// picks up the new template/style content instead of serving stale output.
376+
const mod = server.moduleGraph.getModuleById(componentFile)
377+
if (mod) {
378+
server.moduleGraph.invalidateModule(mod)
379+
}
373380
}
374381
}
375382
}

0 commit comments

Comments
 (0)