From b04d728249e1dbc6ce5ab1beb33835a92583feeb Mon Sep 17 00:00:00 2001 From: JyQAQ <45193678+jyqwq@users.noreply.github.com> Date: Tue, 28 Jul 2026 15:50:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(@vben-core/form-ui):=20=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=20zod=20v4=20=E7=9A=84=20ZodArray=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E8=AF=AF=E7=94=A8=20unwrap()=20=E4=B8=A2=E5=A4=B1=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E5=A4=96=E5=A3=B3=E5=AF=BC=E8=87=B4=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=A4=B1=E8=B4=A5=20(#8207)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/@core/ui-kit/form-ui/src/form-render/helper.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/@core/ui-kit/form-ui/src/form-render/helper.ts b/packages/@core/ui-kit/form-ui/src/form-render/helper.ts index bf904f78..926f09ea 100644 --- a/packages/@core/ui-kit/form-ui/src/form-render/helper.ts +++ b/packages/@core/ui-kit/form-ui/src/form-render/helper.ts @@ -22,6 +22,15 @@ export function getBaseRules(schema?: null | string | ZodType): null | ZodType { return getBaseRules(rawSchema.in as ZodType); } + // In zod v4, ZodArray also has an unwrap() that returns its element type + // (not an outer wrapper). We must not unwrap it, otherwise z.array(T) loses + // its array shell and array values fail validation. + const defType = (rawSchema as unknown as { _zod?: { def: { type: string } } }) + ._zod?.def?.type; + if (defType === 'array') { + return rawSchema; + } + const unwrappedSchema = (rawSchema as UnwrappableZodType).unwrap?.(); if (unwrappedSchema && unwrappedSchema !== rawSchema) { return getBaseRules(unwrappedSchema);