From 48184febedd6b39621ce305ae29089e208ccb0bc Mon Sep 17 00:00:00 2001 From: David Walsh Date: Thu, 21 Sep 2023 13:29:56 -0500 Subject: [PATCH] Fix #20930 - Prevent Firefox start failure by awaiting startUISync event (#20992) * Fix #20930 - Prevent Firefox start failure by awaiting startUISync event * Update documentation --- app/scripts/metamask-controller.js | 2 +- app/scripts/ui.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 4363054e2e90..70ec00c59921 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -3211,7 +3211,7 @@ export default class MetamaskController extends EventEmitter { } _startUISync() { - // Message startUISync is used in MV3 to start syncing state with UI + // Message startUISync is used to start syncing state with UI // Sending this message after login is completed helps to ensure that incomplete state without // account details are not flushed to UI. this.emit('startUISync'); diff --git a/app/scripts/ui.js b/app/scripts/ui.js index 570b02c0ba3b..df85aa2f957d 100644 --- a/app/scripts/ui.js +++ b/app/scripts/ui.js @@ -257,7 +257,13 @@ async function start() { extensionPort.onMessage.addListener(messageListener); extensionPort.onDisconnect.addListener(resetExtensionStreamAndListeners); } else { - initializeUiWithTab(activeTab); + const messageListener = async (message) => { + if (message?.data?.method === 'startUISync') { + initializeUiWithTab(activeTab); + extensionPort.onMessage.removeListener(messageListener); + } + }; + extensionPort.onMessage.addListener(messageListener); } function initializeUiWithTab(tab) {