Skip to content

Commit 939d161

Browse files
clydindgp1130
authored andcommittedJan 16, 2025·
fix(@angular/build): perform incremental background file updates with component updates
When HMR is enabled, a change to a lazy route component template may alter the names of lazy chunks. These lazy chunks must be updated within the development server so that any later non-HMR based update will have access to these chunks. To support this, the incremental results from the build process can now emit background file updates that will provide output file changes without triggering client updates. (cherry picked from commit e59946c)
1 parent 069818b commit 939d161

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed
 

‎packages/angular/build/src/builders/application/build-action.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ function* emitOutputResults(
264264
const incrementalResult: IncrementalResult = {
265265
kind: ResultKind.Incremental,
266266
warnings: warnings as ResultMessage[],
267+
// These files need to be updated in the dev server but should not signal any updates
268+
background: hasTemplateUpdates,
267269
added: [],
268270
removed: [],
269271
modified: [],
@@ -281,13 +283,6 @@ function* emitOutputResults(
281283
for (const file of outputFiles) {
282284
removedOutputFiles.delete(file.path);
283285

284-
// Temporarily ignore JS files until Angular compiler plugin refactor to allow
285-
// bypassing application code bundling for template affecting only changes.
286-
// TODO: Remove once refactor is complete.
287-
if (hasTemplateUpdates && /\.js(?:\.map)?$/.test(file.path)) {
288-
continue;
289-
}
290-
291286
const previousHash = previousOutputInfo.get(file.path)?.hash;
292287
let needFile = false;
293288
if (previousHash === undefined) {
@@ -299,6 +294,11 @@ function* emitOutputResults(
299294
}
300295

301296
if (needFile) {
297+
// Updates to non-JS files must signal an update with the dev server
298+
if (!/(?:\.js|\.map)?$/.test(file.path)) {
299+
incrementalResult.background = false;
300+
}
301+
302302
incrementalResult.files[file.path] = {
303303
type: file.type,
304304
contents: file.contents,

‎packages/angular/build/src/builders/application/results.ts

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface FullResult extends BaseResult {
3636

3737
export interface IncrementalResult extends BaseResult {
3838
kind: ResultKind.Incremental;
39+
background?: boolean;
3940
added: string[];
4041
removed: { path: string; type: BuildOutputFileType }[];
4142
modified: string[];

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

+15-9
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export async function* serveWithVite(
217217
});
218218
}
219219

220+
let needClientUpdate = true;
220221
switch (result.kind) {
221222
case ResultKind.Full:
222223
if (result.detail?.['htmlIndexPath']) {
@@ -261,6 +262,9 @@ export async function* serveWithVite(
261262
case ResultKind.Incremental:
262263
assert(server, 'Builder must provide an initial full build before incremental results.');
263264

265+
// Background updates should only update server files/options
266+
needClientUpdate = !result.background;
267+
264268
for (const removed of result.removed) {
265269
const filePath = '/' + normalizePath(removed.path);
266270
generatedFiles.delete(filePath);
@@ -363,15 +367,17 @@ export async function* serveWithVite(
363367
]),
364368
];
365369

366-
await handleUpdate(
367-
normalizePath,
368-
generatedFiles,
369-
assetFiles,
370-
server,
371-
serverOptions,
372-
context.logger,
373-
componentStyles,
374-
);
370+
if (needClientUpdate) {
371+
await handleUpdate(
372+
normalizePath,
373+
generatedFiles,
374+
assetFiles,
375+
server,
376+
serverOptions,
377+
context.logger,
378+
componentStyles,
379+
);
380+
}
375381
} else {
376382
const projectName = context.target?.project;
377383
if (!projectName) {

0 commit comments

Comments
 (0)
Please sign in to comment.