fix: password-change not working with firefox and edge #612

Massimo Melina committed Jun 10, 2024 at 22:54 UTC e2e1993a0a43e561fcdd29010981af4aee98a7a9
1 file changed +4 -2
shared/dialogs.ts
+4 -2
@@ -19,6 +19,7 @@ export interface DialogOptions {
19 position?: [number, number]
20 dialogProps?: Record<string, any>
21 $id?: number
22 + $opening?: NodeJS.Timeout
23 ts?: number
24
25 Container?: FunctionComponent<DialogOptions>
@@ -177,14 +178,15 @@ export function newDialog(options: DialogOptions) {
178 options.ts = ts
179 focusBak.push(document.activeElement) // saving this inside options object doesn't work (didn't dig enough to say why)
180 options = objSameKeys(options, x => isValidElement(x) ? ref(x) : x) as typeof options // encapsulate elements as react will try to write, but valtio makes them readonly
180 - setTimeout(() => { // in case dialogs were just closed, account for window.history delay. This should be harmless as ux is unaffected, and programmatically you already didn't expect this to happen immediately but at state change
181 + options.$opening = setTimeout(() => { // in case dialogs were just closed, account for window.history delay. This should be harmless as ux is unaffected, and programmatically you already didn't expect this to happen immediately but at state change
182 dialogs.push(options)
183 if (options.closable !== false)
184 history.pushState({ $dialog: $id, ts, idx: history.state.idx + 1 }, '')
184 - }, 1)
185 + }, 10) // 10 for firefox, chrome125 seems to be ok with 1
186 return { close }
187
188 function close(v?:any) {
189 + clearTimeout(options.$opening) // in case it was not open yet
190 const i = dialogs.findIndex(x => (x as any).$id === $id)
191 if (i < 0) return
192 if (history.state.$dialog === $id)