Repository navigation
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
When using animate.leave within @for, it seems that @for may fail to render items it is supposed to render.
The provided example includes a @for that displays a sliced window of a list with a maximum of 3 elements. Removing the middle item causes the @for to only display a window of 2 elements, even in scenarios where it should still display 3. Further interaction might also inconsistently reduce the number of shown elements to 1, or even 0, or it may rarely return the number of displayed items to 3. I have yet to find any consistent trigger besides removing the second to last item of a list like this.
Playing around with the list will inevitably lead to NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
Please provide a link to a minimal reproduction of the bug
Please provide the exception or error you saw
Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 20.2.1
Node: 20.19.1
Package Manager: npm 10.8.2
OS: linux x64
Angular: 20.2.3
... common, compiler, compiler-cli, core
Package Version
------------------------------------
@angular-devkit/architect 0.2002.1
@angular-devkit/core 20.2.1
@angular-devkit/schematics 20.2.1
@angular/build 20.2.1
@angular/cdk 20.2.1
@angular/cli 20.2.1
@schematics/angular 20.2.1
rxjs 7.8.2
typescript 5.8.3
zone.js 0.15.1
Anything else?
No response
Activity
thePunderWoman commentedon Sep 4, 2025
Thanks for reporting this. We'll look into what's happening.
imaksp commentedon Sep 9, 2025
FYI, I could solve this by using track $index instead of track item in your reproduction. with $track item list with animate.leave behaves in unexpected way.
I also faced one issue with animation timing when using @for inside @if block with class based animate.leave but could not understand to cause fully so not created an issue (solved it by using event version.), with class version I think it was not removing old elements from DOM, even if we update signal array (used in @for) using .set.
sigve10 commentedon Sep 9, 2025
Tracking the index doesn't "solve" the issue. All it does is prevent the leave animation from running, as shifting the list doesn't change the
$index, meaning the@fordoes not see the shifting as an actual change.imaksp commentedon Sep 9, 2025
Hi, you are right, I did not check code in detail, bug is related to element removal on leave. list displays correctly if we add leave func like this:
but this does not animate items correctly, and it doesn't work correctly if we call
animationCompleteafter some delay.sigve10 commentedon Sep 9, 2025
@imaksp If you are looking for a temporary solution, I have updated the stackblitz with a workaround I found.
thePunderWoman commentedon Sep 11, 2025
so it looks like what's happening is when the second to last item is removed, this triggers an update to the last item's index, which causes it to get "moved", which is a remove and add. This is triggering the remove animation, which is what's causing this. We'll see what we can figure out to resolve this.
fix(core): Prevent leave animations on a move operation
fix(core): Prevent leave animations on a move operation
fix(core): Prevent leave animations on a move operation
fix(core): Prevent leave animations on a move operation
fix(core): Prevent leave animations on a move operation (#63745)
fix(core): Prevent leave animations on a move operation (angular#63745)
angular-automatic-lock-bot commentedon Oct 13, 2025
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.