Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 718ff84

Browse files
committed
fix(ngAnimate): ensure that cancelled class-based animations are properly cleaned up
Prior to this fix if the same CSS class was added and removed quickly then the element being animated would be left with a stale cache of the cancelled out animation. This would then result in follow-up animations being added to the previous animation which would then never run. A stale cache was to blame for that. This patch takes care of this issue. Closes #11652
1 parent 1b0d0fd commit 718ff84

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/ngAnimate/animateQueue.js

+7
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,13 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
394394
runner.end();
395395
}
396396

397+
// in the event that the element animation was not cancelled or a follow-up animation
398+
// isn't allowed to animate from here then we need to clear the state of the element
399+
// so that any future animations won't read the expired animation data.
400+
if (!isValidAnimation) {
401+
clearElementAnimationState(element);
402+
}
403+
397404
return;
398405
}
399406

test/ngAnimate/animateSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,22 @@ describe("animations", function() {
10291029

10301030
expect(runner1).not.toBe(runner2);
10311031
}));
1032+
1033+
it('should properly cancel out animations when the same class is added/removed within the same digest',
1034+
inject(function($animate, $rootScope) {
1035+
1036+
parent.append(element);
1037+
$animate.addClass(element, 'red');
1038+
$animate.removeClass(element, 'red');
1039+
$rootScope.$digest();
1040+
1041+
expect(capturedAnimation).toBeFalsy();
1042+
1043+
$animate.addClass(element, 'blue');
1044+
$rootScope.$digest();
1045+
1046+
expect(capturedAnimation[2].addClass).toBe('blue');
1047+
}));
10321048
});
10331049

10341050
describe('should merge', function() {

0 commit comments

Comments
 (0)