Skip to content

Commit f46df7c

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.
1 parent 21a486b commit f46df7c

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ export async function invalidateUpdatedFiles(
5757
}
5858

5959
if (serverApplicationChanged) {
60-
// Clear the server app cache and
61-
// trigger module evaluation before reload to initiate dependency optimization.
62-
const { ɵdestroyAngularServerApp } = (await server.ssrLoadModule('/main.server.mjs')) as {
60+
// Clear the server app cache and trigger module evaluation before reload to initiate dependency optimization.
61+
// The querystring is needed as a workaround for:
62+
// `ɵgetOrCreateAngularServerApp` can be undefined right after an error.
63+
const { ɵdestroyAngularServerApp } = (await server.ssrLoadModule(
64+
`/main.server.mjs?timestamp=${Date.now()}`,
65+
)) as {
6366
ɵdestroyAngularServerApp: typeof destroyAngularServerApp;
6467
};
6568

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

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

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

0 commit comments

Comments
 (0)