feat: migrate to zod v4 and add compatibility with zod v3 as well#6652
feat: migrate to zod v4 and add compatibility with zod v3 as well#6652KurtGokhan wants to merge 10 commits intoTanStack:mainfrom
Conversation
|
Important Review skippedToo many files! This PR contains 300 files, which is 150 over the limit of 150. You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
View your CI Pipeline Execution ↗ for commit 4e2eb8d
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Few things:
-
Check out standard schema for user facing verification (which should be everything in this pr as only external inputs need compatibility), both zod 3 and 4 support it: https://standardschema.dev/
-
To support both zod 3 and zod 4 you need to import both (cant just change imports to zod/v4)
-
Zod should be a peer dependency to let the user bring their zod version
-
You should be importing like
import * as z4 from "zod/v4/core"so you can also support zod mini and not just zod "main"
I would advise checking out https://zod.dev/library-authors
There is not much changes to the user-facing verification. The library already supported standard schema. These changes are for ensuring Zod v4 is used in internal code as well.
Not true. Supporting both versions don't mean you have to use both internally. I use v4 internally.
Zod is used internally in the router plugin. Not just for validation. That's why it's a regular dependency. We just make the version v3|v4 to ensure a single version is installed if user choses to install another version.
Again, this is not about validation. It's used internally, so it's ok to use any library. |
|
@KurtGokhan Sorry, I thought it was for user validation |
Fixes #6138
There are changes in a lot of files, but most are search&replace. The core team could easily recreate this PR if reviewing is going to take too much time.
An overview of the changes:
^3.25.0 || ^4.0.0. This means a 4.x version will be installed, but the packages should also work with a 3.x version if it's greater than 3.25.0.zodimports tozod/v4instead. This ensures that Zod v4 will be used even if somehow v3 got installed (e.g. user decision or compatibility with other packages)catchmethod has changed to the desired behavior, which broke some tests. See this issue on Zod and search types as unknown when using zod catch() #2376.Note: it's easier to review this PR commit-by-commit
Also I recommend having this as a major or minor release, as there could be unseen implications for users.