@@ -32,8 +32,10 @@ import {
3232 assertElementNodes ,
3333 cancelAnimationsIfRunning ,
3434 cancelLeavingNodes ,
35+ cleanupAfterLeaveAnimations ,
3536 cleanupEnterClassData ,
3637 clearLeavingNodes ,
38+ clearLViewNodeAnimationResolvers ,
3739 enterClassMap ,
3840 getClassListFromValue ,
3941 getLViewEnterAnimations ,
@@ -246,7 +248,11 @@ export function ɵɵanimateLeave(value: string | Function): typeof ɵɵanimateLe
246248 return ɵɵanimateLeave ; // For chaining
247249}
248250
249- function runLeaveAnimations ( lView : LView , tNode : TNode , value : string | Function ) : Promise < void > {
251+ function runLeaveAnimations (
252+ lView : LView ,
253+ tNode : TNode ,
254+ value : string | Function ,
255+ ) : { promise : Promise < void > ; resolve : VoidFunction } {
250256 const { promise, resolve} = promiseWithResolvers < void > ( ) ;
251257 const nativeElement = getNativeByTNode ( tNode , lView ) as Element ;
252258
@@ -255,22 +261,23 @@ function runLeaveAnimations(lView: LView, tNode: TNode, value: string | Function
255261 const renderer = lView [ RENDERER ] ;
256262 const ngZone = lView [ INJECTOR ] . get ( NgZone ) ;
257263 allLeavingAnimations . add ( lView ) ;
264+ ( getLViewLeaveAnimations ( lView ) . get ( tNode . index ) ! . resolvers ??= [ ] ) . push ( resolve ) ;
258265
259266 const activeClasses = getClassListFromValue ( value ) ;
260267 if ( activeClasses && activeClasses . length > 0 ) {
261268 animateLeaveClassRunner (
262269 nativeElement as HTMLElement ,
263270 tNode ,
271+ lView ,
264272 activeClasses ,
265273 renderer ,
266274 ngZone ,
267- resolve ,
268275 ) ;
269276 } else {
270277 resolve ( ) ;
271278 }
272279
273- return promise ;
280+ return { promise, resolve } ;
274281}
275282
276283/**
@@ -280,13 +287,14 @@ function runLeaveAnimations(lView: LView, tNode: TNode, value: string | Function
280287function animateLeaveClassRunner (
281288 el : HTMLElement ,
282289 tNode : TNode ,
290+ lView : LView ,
283291 classList : string [ ] ,
284292 renderer : Renderer ,
285293 ngZone : NgZone ,
286- resolver : VoidFunction ,
287294) {
288295 cancelAnimationsIfRunning ( el , renderer ) ;
289296 const cleanupFns : Function [ ] = [ ] ;
297+ const resolvers = getLViewLeaveAnimations ( lView ) . get ( tNode . index ) ?. resolvers ;
290298
291299 const handleOutAnimationEnd = ( event : AnimationEvent | TransitionEvent | CustomEvent ) => {
292300 // this early exit case is to prevent issues with bubbling events that are from child element animations
@@ -308,36 +316,29 @@ function animateLeaveClassRunner(
308316 renderer . removeClass ( el , item ) ;
309317 }
310318 }
311- }
312- resolver ( ) ;
313- for ( const fn of cleanupFns ) {
314- fn ( ) ;
319+ cleanupAfterLeaveAnimations ( resolvers , cleanupFns ) ;
320+ clearLViewNodeAnimationResolvers ( lView , tNode ) ;
315321 }
316322 } ;
317323
318324 ngZone . runOutsideAngular ( ( ) => {
319325 cleanupFns . push ( renderer . listen ( el , 'animationend' , handleOutAnimationEnd ) ) ;
320326 cleanupFns . push ( renderer . listen ( el , 'transitionend' , handleOutAnimationEnd ) ) ;
321327 } ) ;
322-
323328 trackLeavingNodes ( tNode , el ) ;
324-
325329 for ( const item of classList ) {
326330 renderer . addClass ( el , item ) ;
327331 }
328-
332+ // In the case that the classes added have no animations, we need to remove
333+ // the element right away. This could happen because someone is intentionally
334+ // preventing an animation via selector specificity.
329335 ngZone . runOutsideAngular ( ( ) => {
330336 requestAnimationFrame ( ( ) => {
331- // In the case that the classes added have no animations, we need to remove
332- // the element right away. This could happen because someone is intentionally
333- // preventing an animation via selector specificity.
334337 determineLongestAnimation ( el , longestAnimations , areAnimationSupported ) ;
335338 if ( ! longestAnimations . has ( el ) ) {
336339 clearLeavingNodes ( tNode , el ) ;
337- resolver ( ) ;
338- for ( const fn of cleanupFns ) {
339- fn ( ) ;
340- }
340+ cleanupAfterLeaveAnimations ( resolvers , cleanupFns ) ;
341+ clearLViewNodeAnimationResolvers ( lView , tNode ) ;
341342 }
342343 } ) ;
343344 } ) ;
@@ -438,8 +439,8 @@ function queueEnterAnimations(lView: LView) {
438439 const enterAnimations = lView [ ANIMATIONS ] ?. enter ;
439440 if ( enterAnimations ) {
440441 const animationQueue = lView [ INJECTOR ] . get ( ANIMATION_QUEUE ) ;
441- for ( const [ _ , animateFns ] of enterAnimations ) {
442- for ( const animateFn of animateFns ) {
442+ for ( const [ _ , nodeAnimations ] of enterAnimations ) {
443+ for ( const animateFn of nodeAnimations . animateFns ) {
443444 animationQueue . queue . add ( animateFn ) ;
444445 }
445446 }
0 commit comments