Просмотр исходного кода

fix(ui): prevent double-close and fix dialog replacement

David Hill 4 недель назад
Родитель
Сommit
7caf59b433
1 измененных файлов с 11 добавлено и 2 удалено
  1. 11 2
      packages/ui/src/context/dialog.tsx

+ 11 - 2
packages/ui/src/context/dialog.tsx

@@ -28,15 +28,18 @@ const Context = createContext<ReturnType<typeof init>>()
 
 function init() {
   const [active, setActive] = createSignal<Active | undefined>()
+  let closing = false
 
   const close = () => {
     const current = active()
-    if (!current) return
+    if (!current || closing) return
+    closing = true
     current.onClose?.()
     current.setClosing(true)
     setTimeout(() => {
       current.dispose()
       setActive(undefined)
+      closing = false
     }, 100)
   }
 
@@ -55,7 +58,13 @@ function init() {
   })
 
   const show = (element: DialogElement, owner: Owner, onClose?: () => void) => {
-    close()
+    // Immediately dispose any existing dialog when showing a new one
+    const current = active()
+    if (current) {
+      current.dispose()
+      setActive(undefined)
+    }
+    closing = false
 
     const id = Math.random().toString(36).slice(2)
     let dispose: (() => void) | undefined