Skip to content

Commit 455b147

Browse files
fix(core): fixes timing issues with enter animations (#62925)
In some patterns, `element.getAnimations()` will be an empty array despite the animation class being present during animation start and the style sheet showing a keyframe animation. Moving the longest animation check to the end resolves this problem. fixes: #62923 PR Close #62925
1 parent d05138a commit 455b147

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

packages/core/src/render3/instructions/animation.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ export function ɵɵanimateEnter(value: string | Function): typeof ɵɵanimateEn
6969
// Retrieve the actual class list from the value. This will resolve any resolver functions from
7070
// bindings.
7171
const activeClasses = getClassListFromValue(value);
72-
73-
let longestAnimation: LongestAnimation | undefined;
7472
const cleanupFns: Function[] = [];
7573

7674
// In the case where multiple animations are happening on the element, we need
@@ -79,8 +77,6 @@ export function ɵɵanimateEnter(value: string | Function): typeof ɵɵanimateEn
7977
// gets removed early.
8078
const handleAnimationStart = (event: AnimationEvent | TransitionEvent) => {
8179
setupAnimationCancel(event, activeClasses, renderer);
82-
longestAnimation = getLongestAnimation(event);
83-
8480
const eventName = event instanceof AnimationEvent ? 'animationend' : 'transitionend';
8581
ngZone.runOutsideAngular(() => {
8682
cleanupFns.push(renderer.listen(nativeElement, eventName, handleInAnimationEnd));
@@ -89,7 +85,7 @@ export function ɵɵanimateEnter(value: string | Function): typeof ɵɵanimateEn
8985

9086
// When the longest animation ends, we can remove all the classes
9187
const handleInAnimationEnd = (event: AnimationEvent | TransitionEvent) => {
92-
animationEnd(event, nativeElement, longestAnimation, activeClasses, renderer, cleanupFns);
88+
animationEnd(event, nativeElement, activeClasses, renderer, cleanupFns);
9389
};
9490

9591
// We only need to add these event listeners if there are actual classes to apply
@@ -406,11 +402,11 @@ function isLongestAnimation(
406402
function animationEnd(
407403
event: AnimationEvent | TransitionEvent,
408404
nativeElement: HTMLElement,
409-
longestAnimation: LongestAnimation | undefined,
410405
classList: string[] | null,
411406
renderer: Renderer,
412407
cleanupFns: Function[],
413408
) {
409+
const longestAnimation = getLongestAnimation(event);
414410
if (isLongestAnimation(event, nativeElement, longestAnimation)) {
415411
// Now that we've found the longest animation, there's no need
416412
// to keep bubbling up this event as it's not going to apply to

0 commit comments

Comments
 (0)