Skip to content

AnimationPlayer sometimes throws #26095

Closed as not planned
Closed as not planned

Description

@bob-lee

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

I wanted my directive plays an animation on host element while certain conditions met. To iterate animation, I shortly played with animation-iteration-count with no success, managed to make it work using AnimationPlayer.play(), reset() and onDone(GitHub repo here).

But if it played an animation then the host component gets destroyed, it throws:

ERROR Error: Uncaught (in promise): Error: Unable to find the timeline player referenced by 1
Error: Unable to find the timeline player referenced by 1
    at TimelineAnimationEngine.push../node_modules/@angular/animations/fesm5/browser.js.TimelineAnimationEngine._getPlayer (browser.js:2183)
    at TimelineAnimationEngine.push../node_modules/@angular/animations/fesm5/browser.js.TimelineAnimationEngine.command (browser.js:2203)
    at InjectableAnimationEngine.push../node_modules/@angular/animations/fesm5/browser.js.AnimationEngine.process (browser.js:3786)
    at AnimationRenderer.push../node_modules/@angular/platform-browser/fesm5/animations.js.AnimationRenderer.setProperty (animations.js:288)
    at issueAnimationCommand (animations.js:96)
    at RendererAnimationPlayer.push../node_modules/@angular/platform-browser/fesm5/animations.js.RendererAnimationPlayer._command (animations.js:75)
    at RendererAnimationPlayer.push../node_modules/@angular/platform-browser/fesm5/animations.js.RendererAnimationPlayer.reset (animations.js:90)
    at NgIdleClickDirective.push../dist/ng-idle-click/fesm5/ng-idle-click.js.NgIdleClickDirective.playDefaultAnimation (ng-idle-click.js:165)
    at NgIdleClickDirective.animationDone (ng-idle-click.js:78)
    at animations.js:172
    at TimelineAnimationEngine.push../node_modules/@angular/animations/fesm5/browser.js.TimelineAnimationEngine._getPlayer (browser.js:2183)
    at TimelineAnimationEngine.push../node_modules/@angular/animations/fesm5/browser.js.TimelineAnimationEngine.command (browser.js:2203)
    at InjectableAnimationEngine.push../node_modules/@angular/animations/fesm5/browser.js.AnimationEngine.process (browser.js:3786)
    at AnimationRenderer.push../node_modules/@angular/platform-browser/fesm5/animations.js.AnimationRenderer.setProperty (animations.js:288)
    at issueAnimationCommand (animations.js:96)
    at RendererAnimationPlayer.push../node_modules/@angular/platform-browser/fesm5/animations.js.RendererAnimationPlayer._command (animations.js:75)
    at RendererAnimationPlayer.push../node_modules/@angular/platform-browser/fesm5/animations.js.RendererAnimationPlayer.reset (animations.js:90)
    at NgIdleClickDirective.push../dist/ng-idle-click/fesm5/ng-idle-click.js.NgIdleClickDirective.playDefaultAnimation (ng-idle-click.js:165)
    at NgIdleClickDirective.animationDone (ng-idle-click.js:78)
    at animations.js:172
    at resolvePromise (zone.js:814)
    at zone.js:877
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:4053)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
    at drainMicroTaskQueue (zone.js:595)
    at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:500)
    at invokeTask (zone.js:1540)
    at IDBRequest.globalZoneAwareCallback (zone.js:1566)

Expected behavior

AnimationPlayer didn't throw when a player is being reused by calling reset() / destroy() and play().

Minimal reproduction of the problem with instructions

Tried to reproduce on Stackblitz but couldn't (it didn't throw).

Could reproduce on live app by following steps below:

  1. Log in here
  2. On devtools' network tab, throttle with long latency, say 2.5s to make it animate
  3. Go into Issues group, add any note and save (button should be animated)
  4. Click user photo and logout (should throw)

What is the motivation / use case for changing the behavior?

Environment


Angular version: 6.0.3


Browser:
- [x] Chrome (desktop) version 69
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 8.11.2  
- Platform:  Windows

Others:

Activity

  1. added
    area: animations
    on Sep 25, 2018
  2. added this to the needsTriage milestone on Sep 25, 2018
  3. modified the milestones: needsTriage, Backlog on Sep 27, 2018
  4. MurhafSousli commented on Oct 20, 2018

    @MurhafSousli

    I have the same issue, I want to play leave animation on child elements when the parent component is destroyed but the player throws the same error

  5. added
    P4
    and removed on Oct 1, 2020
  6. qaxqaxqax commented on Nov 22, 2020

    @qaxqaxqax

    Hello,
    Let me share my experience about this behaviour. I had a very similar error message when I created two players from the same AnimationFactory. For the first play the onDone method have not been called after the second play it turned into the error. My workaround was to build a new instance from the animation factory with the same parameters and create two independent players. Error gone.

  7. intellix commented on Jan 31, 2021

    @intellix

    This ones killing us as well. There seems to be a memory leak in animating the same element over and over again as can be seen here: https://stackblitz.com/edit/angular-ivy-basic-animation

    To get around it, we destroy the previous player beforehand and that seems to fix it. Now we're getting this thrown:

    spin() {
      if (this.player) {
        this.player.destroy();
      }
    
      this.player = this.builder.build([...]).create(this.wheel.nativeElement);
      this.player.onStart(() => ...);
      this.player.onDone(() => ...);
      this.player.play();
    }

    Tried doing a setTimeout(() => ) around the next play but it doesn't seem to matter. The whole thing just throws randomly. I think the only workaround right now is to wrap the destroy in a try/catch?

  8. NicoBrg-WDG commented on May 27, 2023

    @NicoBrg-WDG

    I ran into the same problem today when animating the same few divs over and over with to different animations (slide in, slide out).

    At first, each time I wanted to animate a div I was creating a new factory and a new player with no concern for memory just to test this player thing. After making it work like I wanted I tried to write cleaner code by:

    1. extracting the factories in variables, one factory per animation (2 factories total),
    2. reusing the existing players, only creating a new player for divs that didn't have one and calling reset()/restart()/play() on the existing one

    I tried all the combinations but the reset thing didn't seem to work, so I tried to call destroy() on the existing player and create a new one, but the destroy() call was throwing the Unable to find the timeline player referenced by 1 error. I checked my code and I was only calling destroy() only once so I expected the player to be destroyed properly.
    By debugging the destroy() method in Chrome Dev Tools I noticed that even though my destroy() call was failing, the browser was still holding references to multiple other players. The weird thing was that all the players had the same id, either 0 or 1, not sur how this is possible.

    In my case I figured that having my 2 factories in variables that I was calling to create players seemed to result in this weird behavior, so now I create a factory each time I create a player, and I call destroy() on each player before creating a new one, it all seems to work. No player is left behind.

  9. thePunderWoman commented on Aug 21, 2025

    @thePunderWoman
    Contributor

    This issue was closed as obsolete due to the introduction of the new animate.enter and animate.leave APIs. The @angular/animations package is now deprecated and will be removed in Angular v23. We hope you give the new APIs a try.

  10. angular-automatic-lock-bot commented on Sep 21, 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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4area: animationsfreq2: mediumtype: bug/fix

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions