Skip to content

Commit

Permalink
fix(@angular/ssr): disable component boostrapping when running route …
Browse files Browse the repository at this point in the history
…extraction

This commit fixes an issue where the components where still being
boostrapped when using `provideAppInitializer`

Closes angular#29131
  • Loading branch information
alan-agius4 committed Dec 19, 2024
1 parent 0718e1b commit 7c462af
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions packages/angular/ssr/src/routes/ng-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<unknown>;
},
provide: ɵENABLE_ROOT_COMPONENT_BOOTSTRAP,
useValue: false,
},
]);

Expand Down

0 comments on commit 7c462af

Please sign in to comment.