Skip to content

Commit b22681a

Browse files
committed
fix(uiGrid): Fix race condition in data watcher
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
1 parent a6086ea commit b22681a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: src/js/core/directives/ui-grid.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
}
7979
}
8080

81+
var mostRecentData;
82+
8183
function dataWatchFunction(newData) {
8284
// gridUtil.logDebug('dataWatch fired');
8385
var promises = [];
@@ -90,6 +92,8 @@
9092
}
9193
}
9294

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

120124
$q.all(promises).then(function() {
121-
self.grid.modifyRows(newData)
125+
// use most recent data, rather than the potentially outdated data passed into watcher handler
126+
self.grid.modifyRows(mostRecentData)
122127
.then(function () {
123128
// if (self.viewport) {
124129
self.grid.redrawInPlace(true);

0 commit comments

Comments
 (0)