Bug 1067173 - Bail out early if _resizeGrid() is called before the page has loaded. f=Mardak, r=adw, a=sledru
authorTim Taubert <ttaubert@mozilla.com>
Sat, 20 Sep 2014 20:41:18 +0200
changeset 216844 c043fec932a6
parent 216843 008eb429e655
child 216845 a703ff0c7861
push id3939
push userryanvm@gmail.com
push date2014-09-25 15:14 +0000
treeherdermozilla-beta@c043fec932a6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw, sledru
bugs1067173
milestone33.0
Bug 1067173 - Bail out early if _resizeGrid() is called before the page has loaded. f=Mardak, r=adw, a=sledru
browser/base/content/newtab/grid.js
--- a/browser/base/content/newtab/grid.js
+++ b/browser/base/content/newtab/grid.js
@@ -188,16 +188,23 @@ let gGrid = {
         this.createSite(links[i], cells[i]);
     }
   },
 
   /**
    * Make sure the correct number of rows and columns are visible
    */
   _resizeGrid: function Grid_resizeGrid() {
+    // If we're somehow called before the page has finished loading,
+    // let's bail out to avoid caching zero heights and widths.
+    // We'll be called again when the load event fires.
+    if (document.readyState != "complete") {
+      return;
+    }
+
     // Save the cell's computed height/width including margin and border
     if (this._cellMargin === undefined) {
       let refCell = document.querySelector(".newtab-cell");
       this._cellMargin = parseFloat(getComputedStyle(refCell).marginTop) * 2;
       this._cellHeight = refCell.offsetHeight + this._cellMargin;
       this._cellWidth = refCell.offsetWidth + this._cellMargin;
     }