router: Start server function validator only supports the `ValidatorFn` shape (so things like Zod don't work as expected)

Which project does this relate to?

Start

Describe the bug

On the Start v1.81.7, the server function validator middleware does not actually support the options described by its typings.

It accepts AnyValidator (https://github.com/TanStack/router/blob/main/packages/react-router/src/validators.ts#L62-L67).

However, the actual implementation assumes the validator is the ValidatorFn shape (https://github.com/TanStack/router/blob/main/packages/start/src/client/createServerFn.ts#L325-L330).

Looks like nextMiddleware.options.validator in that createServerFn.ts has the any type - any ways to cleanup the types in there as well? If nextMiddleware.options.validator were set to AnyValidator, the issue would have been surfaced right away.

Your Example Website or App

NA

Steps to Reproduce the Bug or Issue

Attempt to use zod, or zod + @tanstack/zod-adapter, with a server function validator and it’ll throw.

Expected behavior

The server function validator supports the validator shapes described in @tanstack/zod-adapter.

Screenshots or Videos

No response

Platform

  • OS: mac
  • Browser: chrome

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments

I just pushed a “mostly” fix for this, but as we’ve been discussing the adoption of the “Standard Validation” schema internally, it might need to be massaged for backwards compatibility.

@chorobin told me to close this

ok then let’s keep this open until @chorobin is back

Yeah, I’m currently upgrading TanStack.com to this new version, so I feel the same pain. @chorobin is on vaycay, but is the most familiar with this code. I’m sure he can whip up a proper fix when he gets back. Let’s let him rest. To your other question, yes, the plan is to support the standard validation schema format and also provide some fallback adapters that not only work across Start and Router, but also Form, etc.

exporting it does not really mean it is public API IMO. it’s public when we add API docs (which we don’t do here)

Happy to - will open it shortly. Just wanted to confirm ya’ll are OK exporting and re-using that function from router - exporting it kind of makes it part of the “public” api surface in a way.

thanks. yes we will probably reuse this from router. if you want, you can also create a PR for this