Skip to content

Conversation

@arturovt
Copy link
Contributor

Fixes crash when platform/app destroys itself during the bootstrapping and stabilization phase. Previously, the code would call applicationRef.injector without checking if the platform was destroyed, resulting in: "Error: Injector has already been destroyed"

This can occur when:

  • Component constructor calls inject(PlatformRef).destroy()
  • AbortSignal triggers during request handling
  • APP_INITIALIZER rejects and causes cleanup
  • Custom guard/resolver logic destroys the platform

Solution: Check applicationRef.destroyed after whenStable() and return error state instead of accessing destroyed injector.

Test: Added test case that destroys app in component constructor to verify graceful handling of this edge case.

@arturovt arturovt force-pushed the fix/angular_ssr_self_destroy branch 2 times, most recently from 366b0fc to 88127de Compare January 12, 2026 17:53
@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels Jan 13, 2026
Fixes crash when platform/app destroys itself during the bootstrapping and
stabilization phase. Previously, the code would call `applicationRef.injector`
without checking if the platform was destroyed, resulting in:
"Error: Injector has already been destroyed"

This can occur when:
- Component constructor calls `inject(PlatformRef).destroy()`
- AbortSignal triggers during request handling
- APP_INITIALIZER rejects and causes cleanup
- Custom guard/resolver logic destroys the platform

Solution: Check `applicationRef.destroyed` after `whenStable()` and return error
state instead of accessing destroyed injector.

Test: Added test case that destroys app in component constructor to
verify graceful handling of this edge case.
@alan-agius4 alan-agius4 force-pushed the fix/angular_ssr_self_destroy branch from 88127de to 02575d6 Compare January 13, 2026 08:10
@dgp1130 dgp1130 merged commit fd1a209 into angular:main Jan 13, 2026
34 checks passed
@dgp1130
Copy link
Collaborator

dgp1130 commented Jan 13, 2026

This PR was merged into the repository. The changes were merged into the following branches:

@arturovt arturovt deleted the fix/angular_ssr_self_destroy branch January 13, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/ssr target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants