Skip to content

Dynamic component + animate.leave leaves orphaned DOM nodes #66794

@mattlewis92

Description

@mattlewis92

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

core

Is this a regression?

No

Description

When using a dynamically inserted component and a leave animation, when triggering the element to show and hide quickly, the element can be retained and duplicated in the DOM

In the linked stackblitz if you click the trigger button repeatedly, you'll see multiple versions of the menu component being retained in the DOM

Image

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/kucxgmx5-6a2vvycd?file=src%2Fexample%2Fcdk-menu-standalone-menu-example.css,src%2Fexample%2Fcdk-menu-standalone-menu-example.html&startScript=start

Please provide the exception or error you saw


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

Angular CLI       : 21.1.2
Angular           : 21.1.1
Node.js           : 20.19.1
Package Manager   : npm 10.8.2
Operating System  : linux x64

┌─────────────────────────────────┬───────────────────┬───────────────────┐
│ Package                         │ Installed Version │ Requested Version │
├─────────────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build                  │ 21.1.2            │ ^21.0.0           │
│ @angular/cdk                    │ 21.1.1            │ ^21.0.0           │
│ @angular/cli                    │ 21.1.2            │ ^21.0.0           │
│ @angular/common                 │ 21.1.1            │ ^21.0.0           │
│ @angular/compiler               │ 21.1.1            │ ^21.0.0           │
│ @angular/compiler-cli           │ 21.1.1            │ ^21.0.0           │
│ @angular/core                   │ 21.1.1            │ ^21.0.0           │
│ @angular/forms                  │ 21.1.1            │ ^21.0.0           │
│ @angular/localize               │ 21.1.1            │ ^21.0.0           │
│ @angular/material               │ 21.1.1            │ ^21.0.0           │
│ @angular/material-luxon-adapter │ 21.1.1            │ ^21.0.0           │
│ @angular/platform-browser       │ 21.1.1            │ ^21.0.0           │
│ @angular/router                 │ 21.1.1            │ ^21.0.0           │
│ rxjs                            │ 7.8.2             │ ~7.8.0            │
│ typescript                      │ 5.9.3             │ ~5.9.2            │
│ zone.js                         │ 0.15.1            │ ~0.15.0           │
└─────────────────────────────────┴───────────────────┴───────────────────┘

Anything else?

This only occurs in zoneless mode - adding provideZoneChangeDetection() fixes the issue

Metadata

Metadata

Labels

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

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions