Skip to content

Commit 15f30e7

Browse files
committed
fix(@angular/ssr): handle undefined ɵgetOrCreateAngularServerApp
This change fixes 'Error: ɵgetOrCreateAngularServerApp is not a function' which can occur when the dev server stops updating if the user saves while the HTML is in an invalid state. Closes #31671
1 parent 21a486b commit 15f30e7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/angular/ssr/src/app-engine.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,17 @@ export class AngularAppEngine {
142142
return null;
143143
}
144144

145+
const { ɵgetOrCreateAngularServerApp } = entryPoint;
146+
if (!ɵgetOrCreateAngularServerApp) {
147+
// Sometimes in Vite `ɵgetOrCreateAngularServerApp` is undefined,
148+
// which causes a runtime error `Error: ɵgetOrCreateAngularServerApp is not a function`
149+
// See: https://github.com/angular/angular-cli/issues/31671
150+
return null;
151+
}
152+
145153
// Note: Using `instanceof` is not feasible here because `AngularServerApp` will
146154
// be located in separate bundles, making `instanceof` checks unreliable.
147-
const ɵgetOrCreateAngularServerApp =
148-
entryPoint.ɵgetOrCreateAngularServerApp as typeof getOrCreateAngularServerApp;
149-
150-
const serverApp = ɵgetOrCreateAngularServerApp({
155+
const serverApp = (ɵgetOrCreateAngularServerApp as typeof getOrCreateAngularServerApp)({
151156
allowStaticRouteRender: AngularAppEngine.ɵallowStaticRouteRender,
152157
hooks: AngularAppEngine.ɵhooks,
153158
});

0 commit comments

Comments
 (0)