Skip to content

fix(@angular/ssr): check whether injector is destroyed #30738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/angular/ssr/src/utils/ng.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ export async function renderAngular(
// Block until application is stable.
await applicationRef.whenStable();

const { destroyed } = applicationRef;

// TODO(alanagius): Find a way to avoid rendering here especially for redirects as any output will be discarded.
const envInjector = applicationRef.injector;
const routerIsProvided = !!envInjector.get(ActivatedRoute, null);
const router = envInjector.get(Router);
const lastSuccessfulNavigation = router.lastSuccessfulNavigation;
const routerIsProvided = destroyed ? false : !!envInjector.get(ActivatedRoute, null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the case when the applicationRef gets destroyed before the rendering phase? Internally in

renderInternal(platformRef, applicationRef)
the environment injector is also required to render the app.

const router = destroyed ? null : envInjector.get(Router);
const lastSuccessfulNavigation = router?.lastSuccessfulNavigation;

if (!routerIsProvided) {
if (!router || !routerIsProvided) {
hasNavigationError = false;
} else if (lastSuccessfulNavigation?.finalUrl) {
hasNavigationError = false;
Expand Down