From d2c6edacb6464b52513dbe467c8b5713abd6a9fc Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 28 Feb 2024 13:27:54 -0600 Subject: Protect against non functions being passed to close callback (#3019) --- src/components/Dialog/index.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/components/Dialog/index.tsx') diff --git a/src/components/Dialog/index.tsx b/src/components/Dialog/index.tsx index 27f43afd3..5c0350274 100644 --- a/src/components/Dialog/index.tsx +++ b/src/components/Dialog/index.tsx @@ -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(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) } -- cgit 1.4.1