Skip to content

Commit 8053f2d

Browse files
committed
fix(@angular/build): ensure ɵgetOrCreateAngularServerApp is always defined after errors
Addresses an issue where could become `ɵgetOrCreateAngularServerApp` undefined after an error, leading to subsequent rendering failures. This change modifies the HMR process to include a timestamp when loading. This ensures the server application is always re-evaluated, preventing stale application states. Closes #31671
1 parent 904ef7a commit 8053f2d

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,12 @@ async function invalidateUpdatedFiles(
598598
}
599599

600600
if (serverApplicationChanged) {
601-
// Clear the server app cache and
602-
// trigger module evaluation before reload to initiate dependency optimization.
603-
const { ɵdestroyAngularServerApp } = (await server.ssrLoadModule('/main.server.mjs')) as {
601+
// Clear the server app cache and trigger module evaluation before reload to initiate dependency optimization.
602+
// The querystring is needed as a workaround for:
603+
// `ɵgetOrCreateAngularServerApp` can be undefined right after an error.
604+
const { ɵdestroyAngularServerApp } = (await server.ssrLoadModule(
605+
`/main.server.mjs?timestamp=${Date.now()}`,
606+
)) as {
604607
ɵdestroyAngularServerApp: typeof destroyAngularServerApp;
605608
};
606609

packages/angular/build/src/tools/vite/middlewares/ssr-middleware.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ export function createAngularSsrInternalMiddleware(
4444
ɵgetOrCreateAngularServerApp: typeof getOrCreateAngularServerApp;
4545
};
4646

47-
// `ɵgetOrCreateAngularServerApp` can be undefined right after an error.
48-
// See: https://github.com/angular/angular-cli/issues/29907
49-
if (!ɵgetOrCreateAngularServerApp) {
50-
return next();
51-
}
52-
5347
const angularServerApp = ɵgetOrCreateAngularServerApp({
5448
allowStaticRouteRender: true,
5549
});

0 commit comments

Comments
 (0)