Skip to content

Commit 3fc2c4c

Browse files
committed
fix(ui): preserve DialogProvider context in dynamically-created dialog roots
Browser-mode dialogs (Settings, Edit Project, Add Project) crashed with 'useDialog must be used within a DialogProvider' because dialog content was mounted in a detached Solid root. Attach createRoot to the caller's owner so the provider/context chain is preserved while keeping disposal. Refs: anomalyco#35132
1 parent 03bff65 commit 3fc2c4c

1 file changed

Lines changed: 37 additions & 40 deletions

File tree

‎packages/ui/src/context/dialog.tsx‎

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
onCleanup,
88
type Owner,
99
type ParentProps,
10-
runWithOwner,
1110
useContext,
1211
type JSX,
1312
startTransition,
@@ -81,45 +80,43 @@ function init() {
8180
let dispose: (() => void) | undefined
8281
let setClosing: ((closing: boolean) => void) | undefined
8382

84-
const node = runWithOwner(owner, () =>
85-
createRoot((d: () => void) => {
86-
dispose = d
87-
const [closing, setClosingSignal] = createSignal(false)
88-
setClosing = setClosingSignal
89-
return (
90-
<Kobalte
91-
modal
92-
open={!closing()}
93-
onOpenChange={(open: boolean) => {
94-
if (open) return
95-
close(id)
96-
}}
97-
>
98-
<Kobalte.Portal>
99-
<Kobalte.Overlay
100-
data-component="dialog-overlay"
101-
style={{ "z-index": String(zIndex) }}
102-
onClick={() => close(id)}
103-
/>
104-
<div
105-
data-dialog-layer={layer}
106-
style={{
107-
position: "fixed",
108-
inset: "0",
109-
"z-index": String(zIndex),
110-
display: "flex",
111-
"align-items": "center",
112-
"justify-content": "center",
113-
"pointer-events": "none",
114-
}}
115-
>
116-
{element()}
117-
</div>
118-
</Kobalte.Portal>
119-
</Kobalte>
120-
)
121-
}),
122-
)
83+
const node = createRoot((d: () => void) => {
84+
dispose = d
85+
const [closing, setClosingSignal] = createSignal(false)
86+
setClosing = setClosingSignal
87+
return (
88+
<Kobalte
89+
modal
90+
open={!closing()}
91+
onOpenChange={(open: boolean) => {
92+
if (open) return
93+
close(id)
94+
}}
95+
>
96+
<Kobalte.Portal>
97+
<Kobalte.Overlay
98+
data-component="dialog-overlay"
99+
style={{ "z-index": String(zIndex) }}
100+
onClick={() => close(id)}
101+
/>
102+
<div
103+
data-dialog-layer={layer}
104+
style={{
105+
position: "fixed",
106+
inset: "0",
107+
"z-index": String(zIndex),
108+
display: "flex",
109+
"align-items": "center",
110+
"justify-content": "center",
111+
"pointer-events": "none",
112+
}}
113+
>
114+
{element()}
115+
</div>
116+
</Kobalte.Portal>
117+
</Kobalte>
118+
)
119+
}, owner)
123120

124121
if (!dispose || !setClosing) return
125122

0 commit comments

Comments
 (0)