@@ -52,7 +52,7 @@ import {
5252} from '../entity.js' ;
5353import { fieldProxy } from './proxies.js' ;
5454import { clone } from '../utils.js' ;
55- import type { Entity } from '../schemaEntity.js' ;
55+ import { hasEffects , type Entity } from '../schemaEntity.js' ;
5656import { unwrapZodType } from '../schemaEntity.js' ;
5757
5858enum FetchStatus {
@@ -843,6 +843,8 @@ function shouldSyncFlash<T extends AnyZodObject, M>(
843843 return options . syncFlashMessage ;
844844}
845845
846+ const effectMapCache = new WeakMap < object , boolean > ( ) ;
847+
846848async function validateField < T extends AnyZodObject , M > (
847849 path : string [ ] ,
848850 validators : FormOptions < T , M > [ 'validators' ] ,
@@ -940,7 +942,7 @@ async function validateField<T extends AnyZodObject, M>(
940942 const unwrapped = unwrapZodType ( nextType ) ;
941943 return unwrapped . effects ? undefined : unwrapped . zodType ;
942944 } else if ( type . _def . typeName == 'ZodArray' ) {
943- const array = type as ZodArray < ZodAny > ;
945+ const array = type as ZodArray < ZodTypeAny > ;
944946 const unwrapped = unwrapZodType ( array . element ) ;
945947 if ( unwrapped . effects ) return undefined ;
946948 return extractValidator ( unwrapped , key ) ;
@@ -952,16 +954,24 @@ async function validateField<T extends AnyZodObject, M>(
952954 if ( 'safeParseAsync' in validators ) {
953955 // Zod validator
954956 // Check if any effects exist for the path, then parse the entire schema.
955- const noEffects = traversePath (
956- validators ,
957- validationPath as FieldPath < typeof validators > ,
958- ( pathData ) => {
959- return extractValidator (
960- unwrapZodType ( pathData . parent ) ,
961- pathData . key
957+ if ( ! effectMapCache . has ( validators ) ) {
958+ effectMapCache . set ( validators , hasEffects ( validators as ZodTypeAny ) ) ;
959+ }
960+
961+ const effects = effectMapCache . get ( validators ) ;
962+
963+ const noEffects = effects
964+ ? undefined
965+ : traversePath (
966+ validators ,
967+ validationPath as FieldPath < typeof validators > ,
968+ ( pathData ) => {
969+ return extractValidator (
970+ unwrapZodType ( pathData . parent ) ,
971+ pathData . key
972+ ) ;
973+ }
962974 ) ;
963- }
964- ) ;
965975
966976 if ( noEffects ) {
967977 const validator = extractValidator (
0 commit comments