angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.39k stars 6.76k forks source link

Component is removed from DOM but not destroyed #30016

Closed SebastianPodgajny closed 1 week ago

SebastianPodgajny commented 1 week ago

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

Component is removed form DOM but ngOnDestroy is not called

Steps to reproduce:

  1. Open stackblitz
  2. Click "Open dialog"
  3. Click "toggle"
    DialogDataExampleDialog ngOnDestroy
  4. Remove dialogRef.overlayRef.dispose(); or @if (true) and repeat 1-3
    DialogDataExampleDialog ngOnDestroy
    TestCmp ngOnDestroy
    DialogOpenerCmp ngOnDestroy

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/yne7sc?file=src%2Fexample%2Fdialog-data-example.ts

Please provide the exception or error you saw

There is no exception, but there should be if calling `dispose` in ngOnDestroy is not supported

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 19.0.0-next.2
Node: 18.20.3
Package Manager: npm 10.2.3
OS: linux x64

Angular: 19.0.0-next.2
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, localize, material, material-moment-adapter
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1900.0-next.2
@angular-devkit/build-angular   19.0.0-next.2
@angular-devkit/core            19.0.0-next.2
@angular-devkit/schematics      19.0.0-next.2
@schematics/angular             19.0.0-next.2
rxjs                            7.4.0
typescript                      5.5.4
zone.js                         0.15.0

Anything else?

No response

crisbeto commented 1 week ago

This is likely the same issue as https://github.com/angular/angular/issues/58075.