Valibot resolver doesn't collect rawCheck issues when base schema fails #13265
Replies: 2 comments
|
This happens due to how Valibot's pipeline mechanics interact with Why this happensIn Valibot, By design in Valibot's pipeline architecture, subsequent pipeline actions like When you switched to Structuring custom checks in ValibotIf you want cross-field or custom validation logic to run alongside base field validations rather than being blocked by an individual field's pipeline failure, the recommended patterns are:
Your custom resolver workaround works because it handles full error formatting on caught |
|
I'd separate the parser choice from which parts of the schema are ready to be checked. With the same schema, input and options, changing Also, For a check that only needs a few fields, Valibot's const schema = v.pipe(
v.object({
email: v.string(),
confirmEmail: v.string(),
age: v.number(),
}),
v.forward(
v.partialCheck(
[['email'], ['confirmEmail']],
input => input.email === input.confirmEmail,
'Emails do not match',
),
['confirmEmail'],
),
);With different email strings and I checked this with Valibot 1.5.0, including an isolated install of your RHF 7.56.3 / resolvers 5.2.2 combination. Resolvers 6.0.2 behaved the same. Your Valibot version and actual schema would still be needed to explain why switching parsers changed the result in your application. The AI-assisted; the parser comparison and resolver checks above were run locally. |
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone,
I ran into an issue where validation errors from
v.rawCheckweren't showing up in my formuntil all other fields were valid first. Once they became valid once, errors would show
correctly even after making those fields invalid again.
Environment
Root issue
When using
v.rawCheckfor custom validation logic, issues I add viaaddIssue()don't appearin the form errors if the base schema validation fails (
dataset.typed === false).The resolver uses
safeParseAsyncwhich doesn't seem to include rawCheck issues when theschema isn't fully "typed":
Workaround
Switching to a custom resolver with parse/parseAsync (which throws a ValiError) that collects all issues from the
pipeline, including rawCheck issues regardless of dataset.typed:
I lack the experience with react-hook-form resolvers and valibot to tell what the expected behavior should be.
Happy to submit a PR if this should be fixed in the resolver.
Full valibotResolver.ts code with workaround
All reactions