restore dialogs history logic as before merge
Massimo Melina committed
Apr 11, 2026 at 16:47 UTC
e2709be4da8721764f6e909900466721ae38cbb9
1 file changed
+9
-4
shared/dialogs.ts
+9
-4
@@ -94,10 +94,15 @@ async function back() {
94
}))
95
}
96
97
-if (history.state?.$dialog) { // it may happen if the user reloads the browser leaving open dialogs
98
- const { $dialog, ...state } = history.state
99
- history.replaceState(state, '')
100
-}
97
+const BASE_STATE = 1
98
+;(async () => {
99
+ // this condition happens if the user reloads the browser leaving open dialogs. Don't pop BASE_STATE as it may contain other state we inherited
100
+ while (history.state?.$dialog !== undefined && history.state.$dialog !== BASE_STATE) {
101
+ history.back()
102
+ await wait(1) // history.state is not changed without this, on chrome123
103
+ }
104
+ history.replaceState({ ...history.state, $dialog: BASE_STATE }, '')
105
+})()
106
107
export function Dialogs(props: HTMLAttributes<HTMLDivElement>) {
108
useEffect(() => domOn('popstate', () => {