Skip to content

fix(@angular/build): perform incremental background file updates with component updates #29373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/angular/build/src/builders/application/build-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ function* emitOutputResults(
const incrementalResult: IncrementalResult = {
kind: ResultKind.Incremental,
warnings: warnings as ResultMessage[],
// These files need to be updated in the dev server but should not signal any updates
background: hasTemplateUpdates,
added: [],
removed: [],
modified: [],
Expand All @@ -281,13 +283,6 @@ function* emitOutputResults(
for (const file of outputFiles) {
removedOutputFiles.delete(file.path);

// Temporarily ignore JS files until Angular compiler plugin refactor to allow
// bypassing application code bundling for template affecting only changes.
// TODO: Remove once refactor is complete.
if (hasTemplateUpdates && /\.js(?:\.map)?$/.test(file.path)) {
continue;
}

const previousHash = previousOutputInfo.get(file.path)?.hash;
let needFile = false;
if (previousHash === undefined) {
Expand All @@ -299,6 +294,11 @@ function* emitOutputResults(
}

if (needFile) {
// Updates to non-JS files must signal an update with the dev server
if (!/(?:\.js|\.map)?$/.test(file.path)) {
incrementalResult.background = false;
}

incrementalResult.files[file.path] = {
type: file.type,
contents: file.contents,
Expand Down
1 change: 1 addition & 0 deletions packages/angular/build/src/builders/application/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface FullResult extends BaseResult {

export interface IncrementalResult extends BaseResult {
kind: ResultKind.Incremental;
background?: boolean;
added: string[];
removed: { path: string; type: BuildOutputFileType }[];
modified: string[];
Expand Down
24 changes: 15 additions & 9 deletions packages/angular/build/src/builders/dev-server/vite-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export async function* serveWithVite(
});
}

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

// Background updates should only update server files/options
needClientUpdate = !result.background;

for (const removed of result.removed) {
const filePath = '/' + normalizePath(removed.path);
generatedFiles.delete(filePath);
Expand Down Expand Up @@ -363,15 +367,17 @@ export async function* serveWithVite(
]),
];

await handleUpdate(
normalizePath,
generatedFiles,
assetFiles,
server,
serverOptions,
context.logger,
componentStyles,
);
if (needClientUpdate) {
await handleUpdate(
normalizePath,
generatedFiles,
assetFiles,
server,
serverOptions,
context.logger,
componentStyles,
);
}
} else {
const projectName = context.target?.project;
if (!projectName) {
Expand Down
Loading