fix: password-change not working with firefox and edge #612
Massimo Melina committed
Jun 10, 2024 at 22:54 UTC
4e2171259643cc352b09a0eac28a45b7cd372676
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>
@@ -175,14 +176,15 @@ export function newDialog(options: DialogOptions) {
176
options.ts = ts
177
focusBak.push(document.activeElement) // saving this inside options object doesn't work (didn't dig enough to say why)
178
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
178
- 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
179
+ 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
180
dialogs.push(options)
181
if (options.closable !== false)
182
history.pushState({ $dialog: $id, ts, idx: history.state.idx + 1 }, '')
182
- }, 1)
183
+ }, 10) // 10 for firefox, chrome125 seems to be ok with 1
184
return { close }
185
186
function close(v?:any) {
187
+ clearTimeout(options.$opening) // in case it was not open yet
188
const i = dialogs.findIndex(x => (x as any).$id === $id)
189
if (i < 0) return
190
if (history.state.$dialog === $id)