Skip to content

animate.enter on new item and animate.leave on existing item don't trigger at the same time in @for #63307

Closed

Description

@princemaple

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

core

Is this a regression?

No

Description

So when I click on inc I expect to see one item sliding in and one item sliding out.

In fact, only the entering item is animated.

And when I remove the .concat([l.at(-1)! + 1]) part, so new items are not created, I can now see the old items going out animated.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-wrhcidhc?file=src%2Fmain.ts

Please provide the exception or error you saw

No obvious error other than animation not working as expected.

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

All latest 20.2

Anything else?

In my own projects, which are still using platformBrowser().bootstrapModule(...) I notice that having BrowserAnimationsModule fixes this problem. I fount out about this because BrowserAnimationsModule is now deprecated and I wanted to remove it sooner rather than later. I ran into this bug while trying to use the new seemingly obvious feature. Simply adding it back makes both enter and leave animations work as expected.

I also tried adding BrowserAnimationsModule in the stackblitz example, to prove my point, but it error-ed. I don't know how to fix the error, I will have to leave it in as a comment.

Activity

  1. changed the title [-]`animate.enter` on new item and `animate.leave` on existing item don't trigger at the same time[/-] [+]`animate.enter` on new item and `animate.leave` on existing item don't trigger at the same time in `@for`[/+] on Aug 21, 2025
  2. added
    area: core
    core: animations
    on Aug 21, 2025
  3. added this to the needsTriage milestone on Aug 21, 2025
  4. thePunderWoman commented on Aug 21, 2025

    @thePunderWoman
    Contributor

    OK so I can see what's happening here. We have some code that prevents duplicate nodes from showing up when nodes are toggled quickly. It cancels and removes the leave animation so that the enter one can fire safely without layout shift. In this case, because the remove and add to the for loop are happening in the same CD, that protection is cancelling the animation on the leaving node.

    We'll see if there's a fix that can keep the duplicate node prevention while allowing leave animations to fire in situations like this.

  5. princemaple commented on Aug 21, 2025

    @princemaple
    Author

    So BrowserAnimationModule somehow making it work was a miracle in my project? 😉
    Or it broke the duplication prevention somehow

  6. thePunderWoman commented on Aug 21, 2025

    @thePunderWoman
    Contributor

    It could be. the Animations Module uses a custom renderer. So it could have been doing something there.

  7. added 2 commits that reference this issue on Aug 22, 2025
    454429c
    029c261
  8. added 5 commits that reference this issue on Aug 22, 2025
    0631e2d
    da144b2
    96dd7a9
    bf0de1c
    7e32d9c
  9. added a commit that references this issue on Aug 22, 2025
    6c421ed
  10. added a commit that references this issue on Aug 22, 2025
    37ead5f
  11. ahimik commented on Aug 25, 2025

    @ahimik

    I’ve been struggling with this issue all the morning and was about to file a bug report, but then I found this thread. Hopefully, it will be resolved soon.
    I can also confirm that it works as expected when using the @angular/animations package.

    My current workaround is to create wrapper and keep enter and leave animations on separate elements, but it looks ugly, requires additional elements and comments why it was made to look so ugly.

  12. thePunderWoman commented on Aug 25, 2025

    @thePunderWoman
    Contributor

    @princemaple @ahimik This should get released with the patch on Wednesday this week. Once that goes out, you should be all set.

  13. princemaple commented on Aug 25, 2025

    @princemaple
    Author

    Cheers @thePunderWoman . A quick off topic Q, do we plan to have any replacements for staggering animations? Or should we use third party animation libraries?

  14. thePunderWoman commented on Aug 25, 2025

    @thePunderWoman
    Contributor
  15. princemaple commented on Aug 25, 2025

    @princemaple
    Author

    Thanks!

  16. ahimik commented on Aug 29, 2025

    @ahimik

    Hi @thePunderWoman ,

    I’ve upgraded my project to version 20.2.1, but it still doesn’t work for me.

    I also forked @princemaple’s StackBlitz here: link
    . Unfortunately, it doesn’t work either. Interestingly, when I experimented with the dependencies earlier, it did work at some point.

    Could you please help me understand what I might be doing wrong?

    Thanks in advance!

  17. princemaple commented on Aug 29, 2025

    @princemaple
    Author

    Huh I don't know why it still doesn't work in this mini repro, it's been working for my own project after the upgrade, FYI. I've completed removed animations package and BrowserAnimationsModule.

  18. thePunderWoman commented on Aug 29, 2025

    @thePunderWoman
    Contributor

    @ahimik You'd want to update to 20.2.2. That's the patch that went out on Wednesday.

    And I can confirm that updating the repro link to that version results in it working. :D

  19. ahimik commented on Aug 29, 2025

    @ahimik

    @thePunderWoman , sorry. Got confused about versions. Works like a charm now, thank You!

  20. angular-automatic-lock-bot commented on Sep 29, 2025

    @angular-automatic-lock-bot

    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.

  21. locked and limited conversation to collaborators on Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area: corecore: animationsstate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions