Bug 1442187: Wait until next tick after popupshown before resolving show(). r?Gijs draft
authorKris Maglione <maglione.k@gmail.com>
Thu, 01 Mar 2018 18:31:14 -0800
changeset 762319 a9d89920a14cc7a7c14da70bb07b35625769041a
parent 761864 9683f24ff8ec5ba768c4a0a124d8439c228b2c8b
push id101139
push usermaglione.k@gmail.com
push dateFri, 02 Mar 2018 02:31:32 +0000
reviewersGijs
bugs1442187
milestone60.0a1
Bug 1442187: Wait until next tick after popupshown before resolving show(). r?Gijs With the migration of Promise microtasks to the main microtask queue, promise resolution handlers are now called immediately after any JS event listener returns. The result of this is that in the case of the show() method, the resolution handlers now run before the view's own popupshown handlers run and the view is set active, which breaks handlers which expect it to act more sensibly. By deferring the resolution until the next tick, the resolution handlers are called when the view is visible and in a consistent state. MozReview-Commit-ID: C7697CBoHFt
browser/components/customizableui/CustomizableUI.jsm
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -4288,17 +4288,20 @@ OverflowableToolbar.prototype = {
       PanelMultiView.openPopup(this._panel, anchor || this._chevron, {
         triggerEvent: aEvent,
       }).catch(Cu.reportError);
       this._chevron.open = true;
 
       this._panel.addEventListener("popupshown", () => {
         this._panel.addEventListener("dragover", this);
         this._panel.addEventListener("dragend", this);
-        resolve();
+        // Wait until the next tick to resolve so all popupshown
+        // handlers have a chance to run before our promise resolution
+        // handlers do.
+        Services.tm.dispatchToMainThread(resolve);
       }, {once: true});
     });
   },
 
   _onClickChevron(aEvent) {
     if (this._chevron.open) {
       this._chevron.open = false;
       PanelMultiView.hidePopup(this._panel);