Skip to content

Commit a56c55c

Browse files
committed
fix(@angular/build): invalidate component template updates with dev-server SSR
To ensure that the Vite-based dev-server SSR uses updated component template update modules, the server module graph is invalidated when component updates are sent. This currently does a full invalidation but in the future this could potentially be optimized to only update the relevant modules. A fix is also present to correct the component update identifier usage to prevent lookup misses.
1 parent d5ea0f1 commit a56c55c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/angular/build/src/builders/dev-server/vite-server.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ export async function* serveWithVite(
233233
assetFiles.set('/' + normalizePath(outputPath), normalizePath(file.inputPath));
234234
}
235235
}
236+
237+
// Invalidate SSR module graph to ensure that only new rebuild is used and not stale component updates
238+
if (server && browserOptions.ssr && templateUpdates.size > 0) {
239+
server.moduleGraph.invalidateAll();
240+
}
241+
236242
// Clear stale template updates on code rebuilds
237243
templateUpdates.clear();
238244

@@ -256,6 +262,12 @@ export async function* serveWithVite(
256262
'Builder must provide an initial full build before component update results.',
257263
);
258264

265+
// Invalidate SSR module graph to ensure that new component updates are used
266+
// TODO: Use fine-grained invalidation of only the component update modules
267+
if (browserOptions.ssr) {
268+
server.moduleGraph.invalidateAll();
269+
}
270+
259271
for (const componentUpdate of result.updates) {
260272
if (componentUpdate.type === 'template') {
261273
templateUpdates.set(componentUpdate.id, componentUpdate.content);

packages/angular/build/src/tools/vite/plugins/angular-memory-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export async function createAngularMemoryPlugin(
6666
const requestUrl = new URL(id.slice(1), 'http://localhost');
6767
const componentId = requestUrl.searchParams.get('c');
6868

69-
return (componentId && options.templateUpdates?.get(componentId)) ?? '';
69+
return (componentId && options.templateUpdates?.get(encodeURIComponent(componentId))) ?? '';
7070
}
7171

7272
const [file] = id.split('?', 1);

0 commit comments

Comments
 (0)