Skip to content

feat: migrate to zod v4 and add compatibility with zod v3 as well#6652

Open
KurtGokhan wants to merge 10 commits intoTanStack:mainfrom
KurtGokhan:zod-v4-migration
Open

feat: migrate to zod v4 and add compatibility with zod v3 as well#6652
KurtGokhan wants to merge 10 commits intoTanStack:mainfrom
KurtGokhan:zod-v4-migration

Conversation

@KurtGokhan
Copy link
Contributor

@KurtGokhan KurtGokhan commented Feb 13, 2026

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:

  • Updated all zod versions in package.json files to ^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.
  • Updated all zod imports to zod/v4 instead. This ensures that Zod v4 will be used even if somehow v3 got installed (e.g. user decision or compatibility with other packages)
  • Updates usages of zod. It's used in only a few places that were:
    • Router plugin. Updated the config schema as some v3 APIs were deprecated or had their behavior changed
    • Start plugin (it's config extends the router plugin config)
    • Zod-adapter. Updated it to support v3 and v4 simultaneously. (Perhaps it's better to make another PR to support standard schema instead)
    • Most other usages are in e2e tests, and since all tests pass, I assume there aren't any issues
    • Fixed some type mismatches. For example, the typing of catch method 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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

Important

Review skipped

Too many files!

This PR contains 300 files, which is 150 over the limit of 150.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Feb 13, 2026

View your CI Pipeline Execution ↗ for commit 4e2eb8d

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 1m 37s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 2s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-14 13:16:12 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 13, 2026

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@6652

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@6652

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@6652

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@6652

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@6652

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@6652

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@6652

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@6652

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@6652

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@6652

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@6652

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@6652

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@6652

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@6652

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@6652

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@6652

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@6652

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@6652

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@6652

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@6652

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@6652

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@6652

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@6652

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@6652

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@6652

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@6652

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-fn-stubs@6652

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@6652

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@6652

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@6652

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@6652

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@6652

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@6652

@tanstack/vue-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router@6652

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-devtools@6652

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-ssr-query@6652

@tanstack/vue-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start@6652

@tanstack/vue-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-client@6652

@tanstack/vue-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-server@6652

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@6652

commit: 4e2eb8d

@KurtGokhan KurtGokhan marked this pull request as ready for review February 15, 2026 18:59
@KurtGokhan KurtGokhan mentioned this pull request Feb 15, 2026
Copy link

@R5dan R5dan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@KurtGokhan
Copy link
Contributor Author

KurtGokhan commented Feb 17, 2026

@R5dan

Check out standard schema for user facing verification

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.

To support both zod 3 and zod 4 you need to import both (cant just change imports to zod/v4)

Not true. Supporting both versions don't mean you have to use both internally. I use v4 internally.

Zod should be a peer dependency to let the user bring their zod version

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.

You should be importing like import * as z4 from "zod/v4/core" so you can also support zod mini and not just zod "main"

Again, this is not about validation. It's used internally, so it's ok to use any library.

@R5dan
Copy link

R5dan commented Feb 17, 2026

@KurtGokhan Sorry, I thought it was for user validation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't use zod v4

2 participants