From b22681a3e70675983a8247d01d39df96d9646118 Mon Sep 17 00:00:00 2001 From: Dean Kerr Date: Wed, 23 Dec 2015 17:35:47 +0000 Subject: [PATCH] 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 --- src/js/core/directives/ui-grid.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/js/core/directives/ui-grid.js b/src/js/core/directives/ui-grid.js index 4e91f234b7..63ed0236a2 100644 --- a/src/js/core/directives/ui-grid.js +++ b/src/js/core/directives/ui-grid.js @@ -78,6 +78,8 @@ } } + var mostRecentData; + function dataWatchFunction(newData) { // gridUtil.logDebug('dataWatch fired'); var promises = []; @@ -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); @@ -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);