From 3feecddbba0d0559da10a45ad4040faf8e9d5198 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 19 Dec 2024 06:53:26 +0000 Subject: [PATCH] fix(@angular/ssr): disable component boostrapping when running route extraction This commit fixes an issue where the components where still being boostrapped when using `provideAppInitializer` Closes #29131 --- packages/angular/ssr/src/routes/ng-routes.ts | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/packages/angular/ssr/src/routes/ng-routes.ts b/packages/angular/ssr/src/routes/ng-routes.ts index 681c8cd5c872..8e23b603ca31 100644 --- a/packages/angular/ssr/src/routes/ng-routes.ts +++ b/packages/angular/ssr/src/routes/ng-routes.ts @@ -8,14 +8,12 @@ import { APP_BASE_HREF, PlatformLocation } from '@angular/common'; import { - APP_INITIALIZER, ApplicationRef, Compiler, - ComponentRef, Injector, - inject, runInInjectionContext, ɵConsole, + ɵENABLE_ROOT_COMPONENT_BOOTSTRAP, } from '@angular/core'; import { INITIAL_CONFIG, platformServer } from '@angular/platform-server'; import { @@ -493,16 +491,8 @@ export async function getRoutesFromAngularRouterConfig( useFactory: () => new Console(), }, { - // We cannot replace `ApplicationRef` with a different provider here due to the dependency injection (DI) hierarchy. - // This code is running at the platform level, where `ApplicationRef` is provided in the root injector. - // As a result, any attempt to replace it will cause the root provider to override the platform provider. - // TODO(alanagius): investigate exporting the app config directly which would help with: https://github.com/angular/angular/issues/59144 - provide: APP_INITIALIZER, - multi: true, - useFactory: () => () => { - const appRef = inject(ApplicationRef); - appRef.bootstrap = () => undefined as unknown as ComponentRef; - }, + provide: ɵENABLE_ROOT_COMPONENT_BOOTSTRAP, + useValue: false, }, ]);