Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
nextTick now keeps reference to correct scope.
Browse files Browse the repository at this point in the history
Previously, `nextTick` would decide whether to run the functions based
on the first `scope` argument passed during a given digest cycle.  This
could fail in multiple scenarios ...

1) The first `nextTick` call didn't supply a scope, but subsequent calls did.
2) Multiple components (with different scopes) registered callbacks during the same digest cycle.

This could lead to callbacks being executed when they shouldn't be (if
the first scope registered wasn't $$destroyed, this _this_ scope was),
or callbacks not being executed when they should be (the first scope was
$$destroyed, but this scope wasn't).

I believe that this fixes #8358
  • Loading branch information
Matthew Lee Gilson authored and ThomasBurleson committed May 16, 2016
1 parent d615710 commit e33b775
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/core/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
var queue = nextTick.queue || [];

//-- add callback to the queue
queue.push(callback);
queue.push({scope: scope, callback: callback});

//-- set default value for digest
if (digest == null) digest = true;
Expand All @@ -610,16 +610,18 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
* Trigger digest if necessary
*/
function processQueue() {
var skip = scope && scope.$$destroyed;
var queue = !skip ? nextTick.queue : [];
var digest = !skip ? nextTick.digest : null;
var queue = nextTick.queue;
var digest = nextTick.digest;

nextTick.queue = [];
nextTick.timeout = null;
nextTick.digest = false;

queue.forEach(function(callback) {
callback();
queue.forEach(function(queueItem) {
var skip = queueItem.scope && queueItem.scope.$$destroyed;
if (!skip) {
queueItem.callback();
}
});

if (digest) $rootScope.$digest();
Expand Down

0 comments on commit e33b775

Please sign in to comment.