From 48819a59e7171f7b7ef34f943461e23900d5958f Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Tue, 17 Dec 2024 16:00:00 +0200 Subject: [PATCH] Fix new automation dialog in Firefox (#23319) --- src/common/navigate.ts | 57 ++++++++++--------- .../automation/dialog-new-automation.ts | 2 - 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/common/navigate.ts b/src/common/navigate.ts index a68fd8cb58..a134cf57f1 100644 --- a/src/common/navigate.ts +++ b/src/common/navigate.ts @@ -23,35 +23,36 @@ export const navigate = async (path: string, options?: NavigateOptions) => { console.warn("Navigation blocked, because dialog refused to close"); return false; } - } - return new Promise((resolve) => { - // need to wait for history state to be updated in case a dialog was closed - setTimeout(async () => { - const replace = options?.replace || false; - - if (__DEMO__) { - if (replace) { - history.replaceState( - history.state?.root ? { root: true } : (options?.data ?? null), - "", - `${mainWindow.location.pathname}#${path}` - ); - } else { - mainWindow.location.hash = path; - } - } else if (replace) { - history.replaceState( - history.state?.root ? { root: true } : (options?.data ?? null), - "", - path - ); - } else { - history.pushState(options?.data ?? null, "", path); - } - fireEvent(mainWindow, "location-changed", { - replace, + return new Promise((resolve) => { + // need to wait for history state to be updated in case a dialog was closed + setTimeout(() => { + navigate(path, options).then(resolve); }); - resolve(true); }); + } + const replace = options?.replace || false; + + if (__DEMO__) { + if (replace) { + history.replaceState( + history.state?.root ? { root: true } : (options?.data ?? null), + "", + `${mainWindow.location.pathname}#${path}` + ); + } else { + mainWindow.location.hash = path; + } + } else if (replace) { + history.replaceState( + history.state?.root ? { root: true } : (options?.data ?? null), + "", + path + ); + } else { + history.pushState(options?.data ?? null, "", path); + } + fireEvent(mainWindow, "location-changed", { + replace, }); + return true; }; diff --git a/src/panels/config/automation/dialog-new-automation.ts b/src/panels/config/automation/dialog-new-automation.ts index 835df4b266..02694132ca 100644 --- a/src/panels/config/automation/dialog-new-automation.ts +++ b/src/panels/config/automation/dialog-new-automation.ts @@ -205,7 +205,6 @@ class DialogNewAutomation extends LitElement implements HassDialog { return; } const path = (ev.currentTarget! as any).path; - this.closeDialog(); if (this._mode === "script") { showScriptEditor({ use_blueprint: { path } }); } else { @@ -217,7 +216,6 @@ class DialogNewAutomation extends LitElement implements HassDialog { if (!shouldHandleRequestSelectedEvent(ev)) { return; } - this.closeDialog(); if (this._mode === "script") { showScriptEditor(); } else {