You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Detached elements stay in memory when animated #50533
Which @angular/* package(s) are the source of the bug?
animations
Is this a regression?
No
Description
If you use an animation on the element and toggle it with ngIf, it seems to be staying in the memory according to Detached Elements debugger in Edge. On a brief look it appears that maybe a WeakMap has to be used some place instead of Map:
Please provide a link to a minimal reproduction of the bug
Select the correct frame in the dropdown on that tab (it should say https://stackblitz-starters-vnp1kv.stackblitz.io/)
Toggle element a few times with the button
Press get detached element
Press analyze to see what keeps the elements there (you will see the above screenshot)
Please provide the exception or error you saw
Multiple copies of DOM element stay in memory.
Please provide the environment you discovered this bug in (run ng version)
I noticed it in Angular 12, but it is reproducible in 16 as well, see linked StackBlitz
The StackBlitz doesn't reproduce the issue for me, this is all I see after toggling the element and clicking 'Get Detached Elements':
Yes, now click the ID and it will expand the element behind it. Also, forgot to make sure, since StackBlitz is in an iframe you need to select the right window:
Thanks for your help on the tooling! I'm sorry I don't have a resolution for you but I did notice a couple things that might help someone debugging this:
The detached HTMLDivElements still show in the dev tools even if you remove the @HostBinding() that applies the animation to the host element.
The detached HTMLDivElements disappear if you define the animation in the parent component instead and apply it to the child like <div element @fade>.
This seems to indicate that the animation definition (animations: [...]) is causing its host element to be retained, as opposed to the animation usage (@fade).
Well, not necessarily, although the underlying issue might be the same. The linked issue talks about manually creating animations with builder and player and so on. Here I have the most basic declarative :enter/:leave animation in metadata with 0 fiddling with the stuff that's under the hood.
Activity
garrettld commentedon May 31, 2023
The StackBlitz doesn't reproduce the issue for me, this is all I see after toggling the element and clicking 'Get Detached Elements':

waterplea commentedon May 31, 2023
Yes, now click the ID and it will expand the element behind it. Also, forgot to make sure, since StackBlitz is in an iframe you need to select the right window:
garrettld commentedon Jun 1, 2023
Thanks for your help on the tooling! I'm sorry I don't have a resolution for you but I did notice a couple things that might help someone debugging this:
@HostBinding()that applies the animation to the host element.<div element @fade>.This seems to indicate that the animation definition (
animations: [...]) is causing its host element to be retained, as opposed to the animation usage (@fade).JeanMeche commentedon Jun 3, 2023
Isn't this a dupe of #20585 ?
waterplea commentedon Jun 3, 2023
Well, not necessarily, although the underlying issue might be the same. The linked issue talks about manually creating animations with builder and player and so on. Here I have the most basic declarative :enter/:leave animation in metadata with 0 fiddling with the stuff that's under the hood.
JeanMeche commentedon Jul 3, 2023
Looks like the issue is the hostbinding like here #24197
Having a noop animation on the parent fixes the leak. (
animations: [trigger("noop", [])])Also the leak appears only where there is a
:leaveanimation.JeanMeche commentedon Jul 3, 2023
I've proposed a fix.
fix(animations): Ensure elements are removed from the cache after lea…
fix(animations): Ensure elements are removed from the cache after lea…
fix(animations): Ensure elements are removed from the cache after lea…
JeanMeche commentedon Jul 11, 2023
#50929 has been merged !
fix(animations): Ensure elements are removed from the cache after lea…
angular-automatic-lock-bot commentedon Aug 11, 2023
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.