You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using @conform-to/zod with async: true, the form reloads on each blur event instead of displaying validation errors inline. This happens even when using shouldValidate: "onBlur" in useForm.
Environment
@conform-to/react: ^1.1.5
@conform-to/zod: ^1.1.5
React version: ^18.3.1
Zod version: ^3.23.8
Browser: Chrome
Package Manager: pnpm
Conform Version
v1.1.5
Steps to Reproduce the Bug or Issue
1. Define an Async Zod Schema with superRefine
import{z}from"zod";// Function to create the final schema with required fieldsconstcreateSchema=(formData: FormData)=>{constschemaFields: Record<string,any>={};if(formData.has("companyName")){schemaFields.companyName=z.string({required_error: "Company name is Required"}).trim().min(1,"Company name cannot be empty").superRefine(async(value,ctx)=>{try{constresult=awaitsomeAsyncValidation(value);if(!result){ctx.addIssue({code: z.ZodIssueCode.custom,message: "Async validation failed",});}}catch(error){ctx.addIssue({code: z.ZodIssueCode.custom,message: `Validation error: ${error.message}`,});}});}returnz.object(schemaFields);};exportconstcompanySchema=async(formData: FormData)=>{returnawaitparseWithZod(formData,{schema: createSchema(formData),async: true});};
Another approach is to always keep schema sync and do something like:
// serverif(submission.status!=="success"){returnsubmission.reply();}constisValidAsync=awaitvalidateAsync(submission.value);if(!isValidAsync){returnsubmission.reply({fieldErrors: {companyName: ["This company name is already used"],},});}
Though in both cases the async validations will only run on submit.
Describe the Bug and the Expected Behavior
Description
When using
@conform-to/zod
withasync: true
, the form reloads on each blur event instead of displaying validation errors inline. This happens even when usingshouldValidate: "onBlur"
inuseForm
.Environment
@conform-to/react
:^1.1.5
@conform-to/zod
:^1.1.5
^18.3.1
^3.23.8
Conform Version
v1.1.5
Steps to Reproduce the Bug or Issue
1. Define an Async Zod Schema with
superRefine
2. Use
useForm
withonValidate
andasync: true
3. Expected Behavior
4. Observed Behavior
async: true
prevents the reload but breaks async validation.Important
I am getting this error in the browser console:
Tried multiple solutions as per the documentation, but nothing worked.
What Browsers Are You Seeing the Problem On?
Screenshots or Videos
Additional Context
Findings & Possible Causes
async: true
seems to be causing a full form submission instead of handling validation inline.superRefine
might be interfering with Conform’s async validation mechanism.async: true
.The text was updated successfully, but these errors were encountered: