T
TanStack3w ago
manual-pink

serverValidation with zod

Hello! I’m exploring the server-validation feature in TanStack Form and saw issue #1704 (“Zod errors from server action aren’t propagated to field error”). Is using a Zod schema in createServerValidate({ onServerValidate }) an intended/supported path for server validation (alongside the Standard Schema adapter)?
6 Replies
multiple-amethyst
multiple-amethyst3w ago
It should be. Whether you write the field level errors manually or have it generated from a schema's response, it should allow for server responses to map to fields. The issue points at this not happening though, so this cannot be avoided by simply doing it manually. It seems to be a problem of actually parsing the errors to have it be field level errors
manual-pink
manual-pinkOP3w ago
Thanks for the quick clarification! Since server responses should map to field-level errors, I’d like to open a PR to implement the parsing step. Does this approach look good? Plan: 1. Add a parser that converts schema errors (e.g. Zod ZodError.issues) into the same field-error map used on the client (form/global vs field-scoped). 2. Use it in the server-validation path so field.state.meta.errors updates and subscribed inputs re-render. 3. Add tests and a short docs example for “Server validation with Zod”.
multiple-amethyst
multiple-amethyst3w ago
Sounds good! Here's some pointers in case you go forward with it: 1. There is already a helper for parsing standard schemas which client-side validators use. Hopefully it's accessible for server stuff. Check standardSchemaValidator for reference 2. Use the client-side parsing as example. What's likely happening is that the server error is not doing the same parsing as the client-side errors. 3. Unit tests would be great! We're lacking them for general framework e2e, let alone SSR examples.
manual-pink
manual-pinkOP3w ago
Hi! I'm working on server-side validation error propagation to fields. I found that we can use validators.onSubmit to server validation. Would it be appropriate to use the onSubmit validator to handle server-side validation errors and let them propagate naturally through the existing validation flow? This would avoid the need for manual state manipulation and provide a cleaner, more consistent approach. Or is there a different recommended pattern for server-side field error propagation? Thanks!
manual-pink
manual-pinkOP2w ago
I have PR that already resolved the that issue. so i suggest some new way to solve the problem https://github.com/TanStack/form/pull/1432
GitHub
feat (form-core): Merging Form-level server errors with Field-level...
Instead of the previous serverValidate function just returning a string, we now return an object: const serverValidate = createServerValidate({ ...formOpts, onServerValidate: ({ value }) =&...
multiple-amethyst
multiple-amethyst2w ago
hmm … code coverage aside, has someone reached out to confirm that their issue is fixed with this PR? but wow, 5 months is quite stale. I‘ll have to take a look at it soon

Did you find this page helpful?