From 2d902a06882d585bd25d221fb107495fbdce7b34 Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Wed, 18 Dec 2024 16:53:30 +0200 Subject: [PATCH] Fix integrations dialog (#23328) * Fix integrations dialog * tweak comments --- src/dialogs/make-dialog-manager.ts | 42 ++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/dialogs/make-dialog-manager.ts b/src/dialogs/make-dialog-manager.ts index 2ad97ef200..5dd52af166 100644 --- a/src/dialogs/make-dialog-manager.ts +++ b/src/dialogs/make-dialog-manager.ts @@ -87,15 +87,23 @@ export const showDialog = async ( }; } - // Get the focus targets after the dialog closes - LOADED[dialogTag].closedFocusTargets = ancestorsWithProperty( - deepActiveElement(), - FOCUS_TARGET - ); - - const { state } = mainWindow.history; - // if the same dialog is already open, don't push state if (addHistory) { + const { history } = mainWindow; + if (history.state?.dialog && !OPEN_DIALOG_STACK.length) { + // theres is a dialog state in history, but no dialogs open + // wait for history.back() to update the state + await new Promise((resolve) => { + setTimeout(resolve); + }); + return showDialog( + element, + root, + dialogTag, + dialogParams, + dialogImport, + addHistory + ); + } OPEN_DIALOG_STACK.push({ element, root, @@ -105,16 +113,22 @@ export const showDialog = async ( addHistory, }); const newState = { dialog: dialogTag }; - if (state?.dialog) { - // if the dialog is already open, replace the name - mainWindow.history.replaceState(newState, ""); + if (history.state?.dialog) { + // if a dialog is already open, replace the name + history.replaceState(newState, ""); } else { - // if the dialog is not open, push a new state so back() will close the dialog - mainWindow.history.replaceState({ ...state, opensDialog: true }, ""); - mainWindow.history.pushState(newState, ""); + // if a dialog is not open, push a new state so back() will close the dialog + history.replaceState({ ...history.state, opensDialog: true }, ""); + history.pushState(newState, ""); } } + // Get the focus targets after the dialog closes + LOADED[dialogTag].closedFocusTargets = ancestorsWithProperty( + deepActiveElement(), + FOCUS_TARGET + ); + const dialogElement = await LOADED[dialogTag].element; // Append it again so it's the last element in the root,