Bug 1365574 - Release event loop between react module loading and toolbox react rendering. r=pbro draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 30 Nov 2017 08:34:05 -0800
changeset 714072 c163bb32ba32a887dc5d8b9e9fee10d8dc452849
parent 713183 2d580aeac901ce5c61a4e5445b46906ce3cf33d8
child 744509 3084e606b6e98cf42cbbbfce8ec712777b563d3b
push id93836
push userbmo:poirot.alex@gmail.com
push dateThu, 21 Dec 2017 17:18:34 +0000
reviewerspbro
bugs1365574
milestone59.0a1
Bug 1365574 - Release event loop between react module loading and toolbox react rendering. r=pbro MozReview-Commit-ID: D1M9n3VFdHJ
devtools/client/framework/toolbox.js
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -499,17 +499,25 @@ Toolbox.prototype = {
       if (!toolDef || !toolDef.isTargetSupported(this._target)) {
         this._defaultToolId = "webconsole";
       }
 
       // Start rendering the toolbox toolbar before selecting the tool, as the tools
       // can take a few hundred milliseconds seconds to start up.
       // But wait for toolbar buttons to be set before updating this react component.
       buttonsPromise.then(() => {
-        this.component.setCanRender();
+        // Delay React rendering as Toolbox.open and buttonsPromise are synchronous.
+        // Even if this involve promises, this is synchronous. Toolbox.open already loads
+        // react modules and freeze the event loop for a significant time.
+        // requestIdleCallback allows releasing it to allow user events to be processed.
+        // Use 16ms maximum delay to allow one frame to be rendered at 60FPS
+        // (1000ms/60FPS=16ms)
+        this.win.requestIdleCallback(() => {
+          this.component.setCanRender();
+        }, {timeout: 16});
       });
 
       yield this.selectTool(this._defaultToolId);
 
       // Wait until the original tool is selected so that the split
       // console input will receive focus.
       let splitConsolePromise = promise.resolve();
       if (Services.prefs.getBoolPref(SPLITCONSOLE_ENABLED_PREF)) {