diff --git a/src/dialogs/make-dialog-manager.ts b/src/dialogs/make-dialog-manager.ts index a7c496d960..129349e556 100644 --- a/src/dialogs/make-dialog-manager.ts +++ b/src/dialogs/make-dialog-manager.ts @@ -45,7 +45,8 @@ export const showDialog = async ( root: ShadowRoot | HTMLElement, dialogTag: string, dialogParams: unknown, - dialogImport?: () => Promise + dialogImport?: () => Promise, + addHistory = true ) => { if (!(dialogTag in LOADED)) { if (!dialogImport) { @@ -59,30 +60,31 @@ export const showDialog = async ( }); } - history.replaceState( - { - dialog: dialogTag, - open: false, - oldState: - history.state?.open && history.state?.dialog !== dialogTag - ? history.state - : null, - }, - "" - ); - try { - history.pushState( - { dialog: dialogTag, dialogParams: dialogParams, open: true }, - "" - ); - } catch (err) { - // dialogParams could not be cloned, probably contains callback - history.pushState( - { dialog: dialogTag, dialogParams: null, open: true }, + if (addHistory) { + history.replaceState( + { + dialog: dialogTag, + open: false, + oldState: + history.state?.open && history.state?.dialog !== dialogTag + ? history.state + : null, + }, "" ); + try { + history.pushState( + { dialog: dialogTag, dialogParams: dialogParams, open: true }, + "" + ); + } catch (err) { + // dialogParams could not be cloned, probably contains callback + history.pushState( + { dialog: dialogTag, dialogParams: null, open: true }, + "" + ); + } } - const dialogElement = await LOADED[dialogTag]; dialogElement.showDialog(dialogParams); }; diff --git a/src/state/dialog-manager-mixin.ts b/src/state/dialog-manager-mixin.ts index b75db54c83..acb0c7c5e3 100644 --- a/src/state/dialog-manager-mixin.ts +++ b/src/state/dialog-manager-mixin.ts @@ -8,6 +8,7 @@ interface RegisterDialogParams { dialogShowEvent: keyof HASSDomEvents; dialogTag: keyof HTMLElementTagNameMap; dialogImport: () => Promise; + addHistory?: boolean; } declare global { @@ -38,6 +39,7 @@ export const dialogManagerMixin = >( dialogShowEvent, dialogTag, dialogImport, + addHistory = true, }: RegisterDialogParams) { this.addEventListener(dialogShowEvent, (showEv) => { showDialog( @@ -45,7 +47,8 @@ export const dialogManagerMixin = >( this.shadowRoot!, dialogTag, (showEv as HASSDomEvent).detail, - dialogImport + dialogImport, + addHistory ); }); } diff --git a/src/state/notification-mixin.ts b/src/state/notification-mixin.ts index 4c34ef77d1..22619b4e2f 100644 --- a/src/state/notification-mixin.ts +++ b/src/state/notification-mixin.ts @@ -10,6 +10,7 @@ export default >(superClass: T) => dialogShowEvent: "hass-notification", dialogTag: "notification-manager", dialogImport: () => import("../managers/notification-manager"), + addHistory: false, }); } };