Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 95b7d14

Browse files
committed
fix(sortable): race condition when removing from DOM
1 parent 87eb932 commit 95b7d14

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/sortable.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ angular.module('ui.sortable', [])
4242
scope.$watch(attrs.ngModel+'.length', function() {
4343
// Timeout to let ng-repeat modify the DOM
4444
$timeout(function() {
45-
element.sortable('refresh');
45+
if (!!element.data('ui-sortable')) {
46+
element.sortable('refresh');
47+
}
4648
});
4749
});
4850

test/sortable.spec.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ describe('uiSortable', function() {
2929
});
3030
});
3131

32+
it('should not refresh sortable if destroyed', function() {
33+
inject(function($compile, $rootScope, $timeout) {
34+
var element;
35+
var childScope = $rootScope.$new();
36+
element = $compile('<div><ul ui-sortable ng-model="items"><li ng-repeat="item in items">{{ item }}</li></ul></div>')(childScope);
37+
$rootScope.$apply(function() {
38+
childScope.items = ['One', 'Two', 'Three'];
39+
});
40+
41+
element.remove(element.firstChild);
42+
expect(function() {
43+
$timeout.flush()
44+
}).not.toThrow();
45+
46+
});
47+
});
48+
3249
});
3350

34-
});
51+
});

0 commit comments

Comments
 (0)