Bug 1442187: Wait until next tick after popupshown before resolving show(). r=Gijs
authorKris Maglione <maglione.k@gmail.com>
Thu, 01 Mar 2018 18:31:14 -0800
changeset 461412 2a775fb2d85e9794364569b1bff761459b270c61
parent 461411 9922610d010eb3c579c7f893f67c6f186affc2a8
child 461413 d131285f10c6746a25e51791efff0297719b3420
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1442187
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
@@ -4368,17 +4368,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);