-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
When destroying a platform via PlatformRef.destroy(), the DestroyRef obtained from the platform injector is not marked as destroyed and its onDestroy callbacks are not invoked.
This makes it impossible to reliably attach teardown logic to the platform lifecycle using DestroyRef.
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/stackblitz-starters-27go9cob?file=src%2Fmain.ts
Please provide the exception or error you saw
- `PlatformRef.onDestroy()` is invoked
- `DestroyRef.onDestroy()` is NOT invoked
- `DestroyRef.destroyed` remains false
Please provide the environment you discovered this bug in (run ng version)
❯ ng version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI : 21.1.0
Angular : 21.1.0
Node.js : 20.19.1
Package Manager : npm 10.8.2
Operating System : linux x64
┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build │ 21.1.0 │ ^21.1.0 │
│ @angular/cli │ 21.1.0 │ ^21.1.0 │
│ @angular/common │ 21.1.0 │ ^21.1.0 │
│ @angular/compiler │ 21.1.0 │ ^21.1.0 │
│ @angular/compiler-cli │ 21.1.0 │ ^21.1.0 │
│ @angular/core │ 21.1.0 │ ^21.1.0 │
│ @angular/forms │ 21.1.0 │ ^21.1.0 │
│ @angular/platform-browser │ 21.1.0 │ ^21.1.0 │
│ @angular/router │ 21.1.0 │ ^21.1.0 │
│ rxjs │ 7.8.2 │ ^7.8.1 │
│ typescript │ 5.9.3 │ ^5.9.3 │
└───────────────────────────┴───────────────────┴───────────────────┘
Anything else?
This suggests that the platform injector's DestroyRef is not connected to the platform lifecycle.
As a result, anything created inside the platform injector that relies on DestroyRef for cleanup will never be destroyed, causing lifecycle callbacks to never run and potentially leading to resource leaks.
This breaks the expected lifecycle contract of DestroyRef, which is documented as the standard mechanism for registering teardown logic tied to an injector's lifetime.