Conversation
|
thanks for starting this. however, we need to discuss first whether / how we want to continue with the whole adapter setup |
62bad67 to
2010d15
Compare
|
View your CI Pipeline Execution ↗ for commit 2010d15
☁️ Nx Cloud last updated this comment at |
More templates
@tanstack/arktype-adapter
@tanstack/directive-functions-plugin
@tanstack/eslint-plugin-router
@tanstack/history
@tanstack/react-router
@tanstack/react-router-devtools
@tanstack/react-router-with-query
@tanstack/react-start
@tanstack/react-start-client
@tanstack/react-start-plugin
@tanstack/react-start-server
@tanstack/router-cli
@tanstack/router-core
@tanstack/router-devtools
@tanstack/router-devtools-core
@tanstack/router-generator
@tanstack/router-plugin
@tanstack/router-utils
@tanstack/router-vite-plugin
@tanstack/server-functions-plugin
@tanstack/solid-router
@tanstack/solid-router-devtools
@tanstack/solid-start
@tanstack/solid-start-client
@tanstack/solid-start-plugin
@tanstack/solid-start-server
@tanstack/start-client-core
@tanstack/start-plugin-core
@tanstack/start-server-core
@tanstack/start-server-functions-client
@tanstack/start-server-functions-fetcher
@tanstack/start-server-functions-server
@tanstack/valibot-adapter
@tanstack/virtual-file-routes
@tanstack/zod-adapter
commit: |
|
this fails to build, can you please have a look? https://cloud.nx.app/runs/q1gPhPfKu4/task/tanstack-search-validator-adapters%3Abuild |
|
Build should be fixed There are a few things we should be aware of before merging it:
I believe that for the functionality we are adding, this code introduces too much complexity. Instead, I think we should document how to write a helper function for your Zod / validator. |
yes! do you want to create docs for this? |
|
@niba Is there a reason why we have to specify both a fallback and a default rather than just a fallback. I can't imagine a scenario where you would want a different value for your default vs your fallback. For example sort: fallback(z.enum(['oldest', 'newest']), 'oldest').default('oldest')vs sort: fallback(z.enum(['oldest', 'newest']), 'oldest')I did notice though that when a |
|
@michael-wolfenden They handle different cases, but it's true that you almost always use a combination of them. I also don't know of a scenario where you wouldn't want to use @schiller-manuel const schema = z.object({
page: z.number().default(1),
filter: z.string().default(''),
sort: z.enum(['newest', 'oldest', 'price']).default('newest').catch("newest"),
})
/*
Zod 3 output: {
page?: number | undefined;
filter?: string | undefined;
sort?: unknown;
}
*/
type Zod3Type = StandardSchemaV1.InferInput<typeof schema>
/*
Zod 4 output: {
page?: number | undefined;
filter?: string | undefined;
sort?: z4.core.util.Whatever | "newest" | "oldest" | "price";
} */
type Zod4Type = StandardSchemaV1.InferInput<typeof schemaZ4>I don't understand why Zod4 generates this |
absolutely! |
| }, | ||
| "peerDependencies": { | ||
| "zod": "^3.23.8", | ||
| "zod": "^3.25.0", |
There was a problem hiding this comment.
https://zod.dev/library-authors
With zod 4.0.x released last week, this line needs to be modified slightly to include version four releases.
"zod": "^3.25.0 || ^4.0.0"
This value also needs to be set for devDependencies too.
There was a problem hiding this comment.
A bit annoying for npm users when this version is not 4. Is there any discussion or issue that is attempting to update this?
| @@ -1,4 +1,5 @@ | |||
| import { z } from 'zod' | |||
| import * as z3 from 'zod/v3' | |||
| import * as z4 from 'zod/v4' | |||
There was a problem hiding this comment.
This import should be modified slightly to include the /core path.
import * as z4 from "zod/v4/core";
|
@hanneswidrig thanks for the review! Zod v4 almost supported TanStack Router without requiring an adapter. The only issue was related to type inference when using I forwarded our issue to the Zod team, and they've already fixed the problem we were facing (colinhacks/zod#4851). With this change, the export const Route = createFileRoute('/shop/products/')({
validateSearch: z.object({
page: z.number().default(1),
filter: z.string().default(''),
sort: z.enum(['newest', 'oldest', 'price']).default('newest').catch("newest"),
}),
})I'm waiting for the new release of zod before opening a PR to update the documentation in Tanstack Router. Should we close this one? @schiller-manuel |
|
@niba very cool! thanks for that! yes, let's close this one and create a new one for the docs. |
|
@niba @schiller-manuel This has landed in Zod 4.0.6, apologies for the delay! |
fixes #4322
In Zod v4, we still need a fallback trick to prevent type loss.
Added tests for Zod v4 and the fallback case
related discussion #4092