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 225098 0612379f6b5442fab571d2f48d0f1f119a0eac8d
parent 225097 a3efc9c76eea09db2052e733ffa46ca906f8236e
child 225099 36f2693ea7c1c159ee2a10669ce1e840a977f088
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw, sledru
bugs1067173
milestone34.0a2
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;
     }