Skip to content

Commit 1cff1c2

Browse files
fix: invalidate Vite module graph on template/style HMR updates (#158)
1 parent ec91e5e commit 1cff1c2

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

crates/.DS_Store

6 KB
Binary file not shown.

napi/.DS_Store

6 KB
Binary file not shown.

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

Lines changed: 15 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
}
@@ -654,6 +661,14 @@ export function angular(options: PluginOptions = {}): Plugin[] {
654661
debugHmr('componentIds keys: %O', Array.from(componentIds.keys()))
655662

656663
if (isComponent && hasComponentId) {
664+
// If there's a pending HMR update for this component, the .ts module
665+
// was invalidated by our fs.watch handler (template/style change), not
666+
// by an actual .ts file edit. Skip the full reload — HMR handles it.
667+
if (pendingHmrUpdates.has(ctx.file)) {
668+
debugHmr('skipping full reload — pending HMR update from template/style change')
669+
return []
670+
}
671+
657672
debugHmr('triggering full reload for component file change')
658673
// Component FILE changes require a full reload because:
659674
// - Class definition changes can't be hot-swapped safely

0 commit comments

Comments
 (0)