Skip to content

Commit 2c03a35

Browse files
committed
fix($animate): clear class animations cache if animation is not started
Closes angular#12604 Closes angular#12603
1 parent 6b72598 commit 2c03a35

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/ngAnimate/animate.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1194,8 +1194,11 @@ angular.module('ngAnimate', ['ng'])
11941194
}
11951195

11961196
return cache.promise = runAnimationPostDigest(function(done) {
1197-
var parentNode, parentElement, elementNode = extractElementNode(element);
1197+
var cache, parentNode, parentElement, elementNode = extractElementNode(element);
11981198
if (elementNode) {
1199+
cache = element.data(STORAGE_KEY);
1200+
element.removeData(STORAGE_KEY);
1201+
11991202
parentElement = element.parent();
12001203
parentNode = elementNode.parentNode;
12011204
}
@@ -1206,9 +1209,6 @@ angular.module('ngAnimate', ['ng'])
12061209
return;
12071210
}
12081211

1209-
var cache = element.data(STORAGE_KEY);
1210-
element.removeData(STORAGE_KEY);
1211-
12121212
var state = element.data(NG_ANIMATE_STATE) || {};
12131213
var classes = resolveElementClasses(element, cache, state.active);
12141214
return !classes

test/ngAnimate/animateSpec.js

+37
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,43 @@ describe("ngAnimate", function() {
543543
});
544544
});
545545

546+
it("should clear the setClass element animation cache before the next animation runs", function() {
547+
var animateSpy = jasmine.createSpy();
548+
module(function($animateProvider) {
549+
$animateProvider.register('.track-me', function() {
550+
return {
551+
addClass: animateSpy,
552+
removeClass: animateSpy,
553+
setClass: animateSpy
554+
};
555+
});
556+
});
557+
inject(function($animate, $rootScope, $sniffer, $$rAF) {
558+
var orphanChild = jqLite('<div class="track-me"></div>');
559+
element.append(orphanChild);
560+
orphanChild.remove();
561+
562+
var doneSpy = jasmine.createSpy();
563+
564+
$animate.setClass(orphanChild, 'red', 'blue').then(doneSpy);
565+
$rootScope.$digest();
566+
$animate.triggerCallbacks();
567+
568+
expect(doneSpy).toHaveBeenCalled();
569+
expect(animateSpy).not.toHaveBeenCalled();
570+
571+
var specialChild = jqLite('<div class="track-me"></div>');
572+
element.append(specialChild);
573+
574+
$animate.setClass(specialChild, 'blue', 'gold').then(doneSpy);
575+
$rootScope.$digest();
576+
$animate.triggerReflow();
577+
$animate.triggerCallbacks();
578+
579+
expect(animateSpy).toHaveBeenCalled();
580+
});
581+
});
582+
546583
it("should exclusively animate the setClass animation event with native dom elements", function() {
547584
var count = 0, fallback = jasmine.createSpy('callback');
548585
module(function($animateProvider) {

0 commit comments

Comments
 (0)