From fa3127e467bcb3a2425eedfb06fc110cc6eb7f1e Mon Sep 17 00:00:00 2001 From: Rain <958414905@qq.com> Date: Mon, 9 Oct 2023 12:12:33 +0800 Subject: [PATCH] chore(default): avoid crashing --- .../antd/association-field/Nester.tsx | 14 ++++++++++++++ .../hooks/useIsAllowToSetDefaultValue.tsx | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/packages/core/client/src/schema-component/antd/association-field/Nester.tsx b/packages/core/client/src/schema-component/antd/association-field/Nester.tsx index c951326117..49bb03fda5 100644 --- a/packages/core/client/src/schema-component/antd/association-field/Nester.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/Nester.tsx @@ -39,6 +39,13 @@ const ToOneNester = (props) => { const recordRef = React.useRef(_.omit(record, '__parent')); const isAllowToSetDefaultValue = useCallback(({ form, fieldSchema, collectionField, getInterface }) => { + if (!collectionField) { + if (process.env.NODE_ENV !== 'production') { + console.error(`collectionField should not be ${collectionField}`); + } + return false; + } + // 当 Field component 不是下列组件时,不允许设置默认值 if ( collectionField.target && @@ -85,6 +92,13 @@ const ToManyNester = observer( } const isAllowToSetDefaultValue = useCallback(({ form, fieldSchema, collectionField, getInterface }) => { + if (!collectionField) { + if (process.env.NODE_ENV !== 'production') { + console.error(`collectionField should not be ${collectionField}`); + } + return false; + } + // 当 Field component 不是下列组件时,不允许设置默认值 if ( collectionField.target && diff --git a/packages/core/client/src/schema-settings/hooks/useIsAllowToSetDefaultValue.tsx b/packages/core/client/src/schema-settings/hooks/useIsAllowToSetDefaultValue.tsx index ad0ca5589a..c28fef3944 100644 --- a/packages/core/client/src/schema-settings/hooks/useIsAllowToSetDefaultValue.tsx +++ b/packages/core/client/src/schema-settings/hooks/useIsAllowToSetDefaultValue.tsx @@ -98,6 +98,13 @@ function _isAllowToSetDefaultValue({ ); } + if (!collectionField) { + if (process.env.NODE_ENV !== 'production') { + console.error(`collectionField should not be ${collectionField}`); + } + return false; + } + // 当 Field component 不是下列组件时,不允许设置默认值 if ( collectionField.target &&