From ecaee603bd24c72174a657e6539913bbf937616f Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Sun, 26 Jan 2025 13:04:03 +0800 Subject: [PATCH] fix(useCompile): avoid error (#6141) --- .../src/schema-component/hooks/useCompile.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/core/client/src/schema-component/hooks/useCompile.ts b/packages/core/client/src/schema-component/hooks/useCompile.ts index edcb9fea4a..37a8dcfb87 100644 --- a/packages/core/client/src/schema-component/hooks/useCompile.ts +++ b/packages/core/client/src/schema-component/hooks/useCompile.ts @@ -39,13 +39,23 @@ export const useCompile = ({ noCache }: Props = { noCache: false }) => { // source is Component Object, for example: { 'x-component': "Cascader", type: "array", title: "所属地区(行政区划)" } if (source && typeof source === 'object' && !isValidElement(source)) { - cacheKey = JSON.stringify(source); - shouldCompile = hasVariable(cacheKey); + try { + cacheKey = JSON.stringify(source); + shouldCompile = hasVariable(cacheKey); + } catch (err) { + console.error(err); + shouldCompile = false; + } } // source is Array, for example: [{ 'title': "{{ ('Admin')}}", name: 'admin' }, { 'title': "{{ ('Root')}}", name: 'root' }] if (Array.isArray(source)) { - shouldCompile = hasVariable(JSON.stringify(source)); + try { + shouldCompile = hasVariable(JSON.stringify(source)); + } catch (err) { + console.error(err); + shouldCompile = false; + } } if (shouldCompile) {