From ec2c580aae5b54b25f549779d43512445bf4229d Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 6 Nov 2025 17:58:14 +0200 Subject: [PATCH] Fix Android crash by try/catch dialog open (#9335) --- src/components/Dialog/context.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/components/Dialog/context.ts b/src/components/Dialog/context.ts index 1caa4eac85..b7e3c78d5e 100644 --- a/src/components/Dialog/context.ts +++ b/src/components/Dialog/context.ts @@ -13,6 +13,7 @@ import { type DialogControlRefProps, type DialogOuterProps, } from '#/components/Dialog/types' +import {IS_DEV} from '#/env' import {BottomSheetSnapPoint} from '../../../modules/bottom-sheet/src/BottomSheet.types' export const Context = createContext({ @@ -50,10 +51,28 @@ export function useDialogControl(): DialogOuterProps['control'] { id, ref: control, open: () => { - control.current.open() + if (control.current) { + control.current.open() + } else { + if (IS_DEV) { + console.warn( + 'Attemped to open a dialog control that was not attached to a dialog!\n' + + 'Please ensure that the Dialog is mounted when calling open/close', + ) + } + } }, close: cb => { - control.current.close(cb) + if (control.current) { + control.current.close(cb) + } else { + if (IS_DEV) { + console.warn( + 'Attemped to close a dialog control that was not attached to a dialog!\n' + + 'Please ensure that the Dialog is mounted when calling open/close', + ) + } + } }, }), [id, control],