Skip to content

Commit

Permalink
fix(uiGrid): Fix race condition in data watcher
Browse files Browse the repository at this point in the history
modifyRows is now passed the most recent data that the dataWatchFunction has seen
Fixes race condition when retrieving templates via URL.
$q.all promise in dataWatchFunction would resolve and pass in outdated
grid data from the original dataWatchFunction call.

Fixes #4532
  • Loading branch information
oriondean committed Dec 23, 2015
1 parent a6086ea commit b22681a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/js/core/directives/ui-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
}
}

var mostRecentData;

function dataWatchFunction(newData) {
// gridUtil.logDebug('dataWatch fired');
var promises = [];
Expand All @@ -90,6 +92,8 @@
}
}

mostRecentData = newData;

if (newData) {
// columns length is greater than the number of row header columns, which don't count because they're created automatically
var hasColumns = self.grid.columns.length > (self.grid.rowHeaderColumns ? self.grid.rowHeaderColumns.length : 0);
Expand Down Expand Up @@ -118,7 +122,8 @@
}

$q.all(promises).then(function() {
self.grid.modifyRows(newData)
// use most recent data, rather than the potentially outdated data passed into watcher handler
self.grid.modifyRows(mostRecentData)
.then(function () {
// if (self.viewport) {
self.grid.redrawInPlace(true);
Expand Down

0 comments on commit b22681a

Please sign in to comment.