Fix infinite callstack while opening a popover (#10391)

This commit is contained in:
Sergei Garin 2024-06-27 23:48:03 +03:00 committed by GitHub
parent 19d5bdb9da
commit 201eec3b84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -80,18 +80,22 @@ export function DialogStackRegistrar(props: React.PropsWithChildren<DialogStackI
const idRef = React.useRef(idRaw)
const typeRef = React.useRef(typeRaw)
const ctx = React.useContext(DialogStackContext)
const context = React.useContext(DialogStackContext)
invariant(ctx, 'DialogStackRegistrar must be used within a DialogStackProvider')
invariant(context, 'DialogStackRegistrar must be used within a DialogStackProvider')
const { add, slice } = context
React.useEffect(() => {
const id = idRef.current
const type = typeRef.current
ctx.add({ id, type })
add({ id, type })
return () => {
ctx.slice(id)
slice(id)
}
}, [ctx])
}, [add, slice])
return children
}