react-hook-form / resolvers

📋 Validation resolvers: Yup, Zod, Superstruct, Joi, Vest, Class Validator, io-ts, Nope, computed-types, typanion, Ajv, TypeBox, ArkType, Valibot, effect-ts and VineJS
https://react-hook-form.com/
MIT License
1.72k stars 157 forks source link

Zod and async marks all fields as validating instead of only the one #705

Open walidvb opened 1 month ago

walidvb commented 1 month ago

Describe the bug When using async validation refinments, zodResolver seems to be the culprit in marking all fields as validating once the form is being submitted(as opposed to marking only the async refined fields)

To Reproduce Steps to reproduce the behavior:

  1. Set up a schema with a zodResolver and an Async field
  2. Click on Submit
  3. Only username is validating asyncronously
  4. formState.validatingFields is marking all fields as validating

Interestingly, only clicking the submit button will mark all fields as validating (if validation is triggered by onChange, only the validating field is marked)

Codesandbox link (Required) https://codesandbox.io/p/sandbox/react-hook-form-async-field-validation-forked-5cclc6?file=%2Fsrc%2Findex.js%3A20%2C18

Expected behavior formState.validatingFields should only contain the fields that currently have an async validation running. Fields unaffected by that validation should not be contained in that object.

Screenshots If applicable, add screenshots to help explain your problem.

https://github.com/user-attachments/assets/edc91f22-2749-4ff5-a905-0fa66e9f127c

Desktop (please complete the following information):

I found this issue which seems to be relevant but couldn't find any resolution: https://github.com/react-hook-form/react-hook-form/issues/5744