Protect against non functions being passed to close callback (#3019)

This commit is contained in:
Eric Bailey 2024-02-28 13:27:54 -06:00 committed by GitHub
parent 0c3d55db6f
commit d2c6edacb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 21 additions and 12 deletions

View file

@ -11,6 +11,7 @@ import {useSafeAreaInsets} from 'react-native-safe-area-context'
import {useTheme, atoms as a, flatten} from '#/alf'
import {Portal} from '#/components/Portal'
import {createInput} from '#/components/forms/TextField'
import {logger} from '#/logger'
import {
DialogOuterProps,
@ -56,7 +57,7 @@ export function Outer({
)
const close = React.useCallback<DialogControlProps['close']>(cb => {
if (cb) {
if (cb && typeof cb === 'function') {
closeCallback.current = cb
}
sheet.current?.close()
@ -74,8 +75,16 @@ export function Outer({
const onChange = React.useCallback(
(index: number) => {
if (index === -1) {
closeCallback.current?.()
closeCallback.current = undefined
try {
closeCallback.current?.()
} catch (e: any) {
logger.error(`Dialog closeCallback failed`, {
message: e.message,
})
} finally {
closeCallback.current = undefined
}
onClose?.()
setOpenIndex(-1)
}