From 017c6f232d536b516862d5871d9caeaaf0265213 Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 29 Jun 2022 23:04:49 +0800 Subject: [PATCH] fix(client): cannot read properties of undefined (reading 'target') --- .../hooks/useCollectionManager.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts b/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts index 3b85242c8..365643454 100644 --- a/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts +++ b/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts @@ -43,12 +43,17 @@ export const useCollectionManager = () => { return; } let cName = collectionName; - return fieldNames.reduce((result, curFieldName) => { - const collectionField = getCollectionField(`${cName}.${curFieldName}`); - cName = collectionField.target; - - return collectionField; - }, null); + let collectionField; + while (cName && fieldNames.length > 0) { + const fileName = fieldNames.shift(); + collectionField = getCollectionField(`${cName}.${fileName}`); + if (collectionField?.target) { + cName = collectionField.target; + } else { + cName = null; + } + } + return collectionField; }, getInterface(name: string) { return interfaces[name] ? clone(interfaces[name]) : null;