@@ -18,7 +18,7 @@ import {ENTER_CLASSNAME, LEAVE_CLASSNAME, NG_ANIMATING_CLASSNAME, NG_ANIMATING_S
1818import { AnimationDriver } from './animation_driver' ;
1919import { getOrSetAsInMap , listenOnPlayer , makeAnimationEvent , normalizeKeyframes , optimizeGroupPlayer } from './shared' ;
2020
21- const EMPTY_PLAYER_ARRAY : AnimationPlayer [ ] = [ ] ;
21+ const EMPTY_PLAYER_ARRAY : TransitionAnimationPlayer [ ] = [ ] ;
2222const NULL_REMOVAL_STATE : ElementAnimationState = {
2323 namespaceId : '' ,
2424 setForRemoval : null ,
@@ -708,7 +708,14 @@ export class TransitionAnimationEngine {
708708
709709 if ( this . _namespaceList . length &&
710710 ( this . totalQueuedPlayers || this . collectedLeaveElements . length ) ) {
711- players = this . _flushAnimations ( microtaskId ) ;
711+ const cleanupFns : Function [ ] = [ ] ;
712+ try {
713+ players = this . _flushAnimations ( cleanupFns , microtaskId ) ;
714+ } finally {
715+ for ( let i = 0 ; i < cleanupFns . length ; i ++ ) {
716+ cleanupFns [ i ] ( ) ;
717+ }
718+ }
712719 } else {
713720 for ( let i = 0 ; i < this . collectedLeaveElements . length ; i ++ ) {
714721 const element = this . collectedLeaveElements [ i ] ;
@@ -737,15 +744,15 @@ export class TransitionAnimationEngine {
737744 }
738745 }
739746
740- private _flushAnimations ( microtaskId : number ) : TransitionAnimationPlayer [ ] {
747+ private _flushAnimations ( cleanupFns : Function [ ] , microtaskId : number ) :
748+ TransitionAnimationPlayer [ ] {
741749 const subTimelines = new ElementInstructionMap ( ) ;
742750 const skippedPlayers : TransitionAnimationPlayer [ ] = [ ] ;
743751 const skippedPlayersMap = new Map < any , AnimationPlayer [ ] > ( ) ;
744752 const queuedInstructions : QueuedTransition [ ] = [ ] ;
745753 const queriedElements = new Map < any , TransitionAnimationPlayer [ ] > ( ) ;
746754 const allPreStyleElements = new Map < any , Set < string > > ( ) ;
747755 const allPostStyleElements = new Map < any , Set < string > > ( ) ;
748- const cleanupFns : Function [ ] = [ ] ;
749756
750757 const bodyNode = getBodyNode ( ) ;
751758 const allEnterNodes : any [ ] = this . collectedEnterElements . length ?
@@ -855,7 +862,6 @@ export class TransitionAnimationEngine {
855862 instruction . errors ! . forEach ( error => { msg += `- ${ error } \n` ; } ) ;
856863 } ) ;
857864
858- cleanupFns . forEach ( fn => fn ( ) ) ;
859865 allPlayers . forEach ( player => player . destroy ( ) ) ;
860866 throw new Error ( msg ) ;
861867 }
@@ -1011,7 +1017,6 @@ export class TransitionAnimationEngine {
10111017 player . play ( ) ;
10121018 } ) ;
10131019
1014- cleanupFns . forEach ( fn => fn ( ) ) ;
10151020 return rootPlayers ;
10161021 }
10171022
@@ -1107,20 +1112,16 @@ export class TransitionAnimationEngine {
11071112 const allSubElements = new Set < any > ( ) ;
11081113 const allNewPlayers = instruction . timelines . map ( timelineInstruction => {
11091114 const element = timelineInstruction . element ;
1115+ allConsumedElements . add ( element ) ;
11101116
11111117 // FIXME (matsko): make sure to-be-removed animations are removed properly
11121118 const details = element [ REMOVAL_FLAG ] ;
11131119 if ( details && details . removedBeforeQueried ) return new NoopAnimationPlayer ( ) ;
11141120
11151121 const isQueriedElement = element !== rootElement ;
1116- let previousPlayers : AnimationPlayer [ ] = EMPTY_PLAYER_ARRAY ;
1117- if ( ! allConsumedElements . has ( element ) ) {
1118- allConsumedElements . add ( element ) ;
1119- const _previousPlayers = allPreviousPlayersMap . get ( element ) ;
1120- if ( _previousPlayers ) {
1121- previousPlayers = _previousPlayers . map ( p => p . getRealPlayer ( ) ) ;
1122- }
1123- }
1122+ const previousPlayers =
1123+ ( allPreviousPlayersMap . get ( element ) || EMPTY_PLAYER_ARRAY ) . map ( p => p . getRealPlayer ( ) ) ;
1124+
11241125 const preStyles = preStylesMap . get ( element ) ;
11251126 const postStyles = postStylesMap . get ( element ) ;
11261127 const keyframes = normalizeKeyframes (
0 commit comments