Skip to content

Angular 20.3.4 using createComponent on ng-container creates not destroying itself #64423

@mattiLeBlanc

Description

@mattiLeBlanc

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

core

Is this a regression?

Yes

Description

Since I upgraded from angular 20.3.3 to 20.3.4 I noticed a bug in my dynamic Overlay Component.
The overlay is loaded with Angular Materials showDialog and injects a component reference via the data object. AfterViewInit triggers the creation of the component in the overlay and happy days.
On dialog close/overlay destroy the dynamic components gets destroyed.
Alas, no longer in 20.3.4.

I have 2 reproductions:

Angular 20.3.3 which works: https://stackblitz.com/edit/stackblitz-starters-lzitya3i?file=package.json
Angular 20.3.4 which fails: https://stackblitz.com/edit/stackblitz-starters-l37jc83s?file=package.json

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-l37jc83s?file=package.json

Please provide the exception or error you saw

No error, problem is noticeable in browser

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

Angular CLI: 20.3.5
Node: 22.16.0
Package Manager: npm 8.19.1
OS: darwin arm64
    

Angular: <error>

Package                      Version
------------------------------------
@angular-devkit/architect    0.2003.5
@angular-devkit/core         20.3.5
@angular-devkit/schematics   20.3.5
@schematics/angular          20.3.5

Anything else?

I did my best with the help of AI to confirm if the problem is related to a coding issue, but I think I can conclude that the ngOnDestroy in the overlay component is not cleaning up after itself since the angular upgrade.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimecore: animationsIssues related to `animate.enter` and `animate.leave`

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions