-
-
Notifications
You must be signed in to change notification settings - Fork 762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start server function validator only supports the ValidatorFn
shape (so things like Zod don't work as expected)
#2759
Comments
do you have a minimal example that we can use to debug this? |
@schiller-manuel looks like router already has a Re example - can use the |
thanks. |
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. |
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) |
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. |
Ah ok I see you copied over the Either way, the pushed change did resolve the issue :). There's a type error though that will likely block the build process. |
Getting familiar with the typings for functions / middleware's will take me longer than I have right now, but just one more pitch to somehow get things like |
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. |
Also, if you know how to fix the types, be my guest and PR. It's a high priority, but I just have so much on my plate right now I need to personally defer. |
Sounds good! Re the types I'll see if I can take a look but at first glance it looks like there's a high up front cost just to get familiar with the approach to types in router/start. Might not have enough time today, but perhaps in the next few days. |
is this resolved with the latest releases? |
Yes, but Tanner mentioned "I'm sure he can whip up a proper fix when he gets back" so I wasn't sure if the current fix is temporary. |
ok then let's keep this open until @chorobin is back |
@chorobin told me to close this |
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 thatcreateServerFn.ts
has theany
type - any ways to cleanup the types in there as well? IfnextMiddleware.options.validator
were set toAnyValidator
, 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
Additional context
No response
The text was updated successfully, but these errors were encountered: