Skip to content

Commit 148acbd

Browse files
committedJan 17, 2025·
fix(@angular/build): reset component updates on dev-server index request
An index request from a client browser indicates a full page reload of the application should occur. In this case, the latest full output of the application should be sent to the client which would contain all separate component and incremental updates that have occurred since the last full update from the build system. To provide for this request, the individual component updates that were previously queued are now cleared to avoid reprocessing already present updates within the application output files. (cherry picked from commit 6e416e5)
1 parent 3040272 commit 148acbd

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed
 

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

+1
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ export async function setupServer(
819819
componentStyles,
820820
templateUpdates,
821821
ssrMode,
822+
resetComponentUpdates: () => templateUpdates.clear(),
822823
}),
823824
createRemoveIdPrefixPlugin(externalMetadata.explicitBrowser),
824825
await createAngularSsrTransformPlugin(serverOptions.workspaceRoot),

‎packages/angular/build/src/tools/vite/middlewares/index-html-middleware.ts

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { AngularMemoryOutputFiles, pathnameWithoutBasePath } from '../utils';
1313
export function createAngularIndexHtmlMiddleware(
1414
server: ViteDevServer,
1515
outputFiles: AngularMemoryOutputFiles,
16+
resetComponentUpdates: () => void,
1617
indexHtmlTransformer: ((content: string) => Promise<string>) | undefined,
1718
): Connect.NextHandleFunction {
1819
return function angularIndexHtmlMiddleware(req, res, next) {
@@ -39,6 +40,9 @@ export function createAngularIndexHtmlMiddleware(
3940
return;
4041
}
4142

43+
// A request for the index indicates a full page reload request.
44+
resetComponentUpdates();
45+
4246
server
4347
.transformIndexHtml(req.url, Buffer.from(rawHtml).toString('utf-8'))
4448
.then(async (processedHtml) => {

‎packages/angular/build/src/tools/vite/plugins/setup-middlewares-plugin.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ interface AngularSetupMiddlewaresPluginOptions {
5353
componentStyles: Map<string, ComponentStyleRecord>;
5454
templateUpdates: Map<string, string>;
5555
ssrMode: ServerSsrMode;
56+
resetComponentUpdates: () => void;
5657
}
5758

5859
async function createEncapsulateStyle(): Promise<
@@ -82,6 +83,7 @@ export function createAngularSetupMiddlewaresPlugin(
8283
componentStyles,
8384
templateUpdates,
8485
ssrMode,
86+
resetComponentUpdates,
8587
} = options;
8688

8789
// Headers, assets and resources get handled first
@@ -117,7 +119,12 @@ export function createAngularSetupMiddlewaresPlugin(
117119

118120
server.middlewares.use(angularHtmlFallbackMiddleware);
119121
server.middlewares.use(
120-
createAngularIndexHtmlMiddleware(server, outputFiles, indexHtmlTransformer),
122+
createAngularIndexHtmlMiddleware(
123+
server,
124+
outputFiles,
125+
resetComponentUpdates,
126+
indexHtmlTransformer,
127+
),
121128
);
122129
};
123130
},

0 commit comments

Comments
 (0)
Please sign in to comment.