Skip to content

Commit 3feecdd

Browse files
committed
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
1 parent 9479484 commit 3feecdd

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

packages/angular/ssr/src/routes/ng-routes.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88

99
import { APP_BASE_HREF, PlatformLocation } from '@angular/common';
1010
import {
11-
APP_INITIALIZER,
1211
ApplicationRef,
1312
Compiler,
14-
ComponentRef,
1513
Injector,
16-
inject,
1714
runInInjectionContext,
1815
ɵConsole,
16+
ɵENABLE_ROOT_COMPONENT_BOOTSTRAP,
1917
} from '@angular/core';
2018
import { INITIAL_CONFIG, platformServer } from '@angular/platform-server';
2119
import {
@@ -493,16 +491,8 @@ export async function getRoutesFromAngularRouterConfig(
493491
useFactory: () => new Console(),
494492
},
495493
{
496-
// We cannot replace `ApplicationRef` with a different provider here due to the dependency injection (DI) hierarchy.
497-
// This code is running at the platform level, where `ApplicationRef` is provided in the root injector.
498-
// As a result, any attempt to replace it will cause the root provider to override the platform provider.
499-
// TODO(alanagius): investigate exporting the app config directly which would help with: https://github.com/angular/angular/issues/59144
500-
provide: APP_INITIALIZER,
501-
multi: true,
502-
useFactory: () => () => {
503-
const appRef = inject(ApplicationRef);
504-
appRef.bootstrap = () => undefined as unknown as ComponentRef<unknown>;
505-
},
494+
provide: ɵENABLE_ROOT_COMPONENT_BOOTSTRAP,
495+
useValue: false,
506496
},
507497
]);
508498

0 commit comments

Comments
 (0)