perf(validation): migrate zod → valibot (−17.9 kB gz off public form)#91
Merged
Conversation
First step of the zod->valibot migration. Converts the public-form-reachable validation (shortIdSchema, public-form-view inputValidators, $shortId validateSearch) to valibot's Standard Schema — plugs into TanStack Router validateSearch and Start inputValidator with no adapter (drops zod-adapter here). POC measurement (public-form index chunk): valibot adds 1.3 kB gz; zod's 23.6 kB stays until all client-reachable z.* call-sites are migrated. Net win (~16-20 kB gz off the index) realizes only when zod is fully evicted.
Converts all 5 zodValidator routes ($slug, f/$formId, login, login/email, form-builder edit) + refactors $shortId to a shared helper. Adds src/lib/valibot-search.ts with verified zod-parity helpers for coerce/default/ catch. valibot Standard Schema works directly in validateSearch, so @tanstack/zod-adapter is now fully unused and removed.
FormSchema (localStorage draft collection) -> valibot Standard Schema, which TanStack DB accepts directly. Maps z.custom/.nullable().optional()/.default/ .transform faithfully (v.custom/v.nullish/v.optional w/ default/v.pipe+transform).
…to valibot Converts all server-fn inputValidators (forms, analytics, submissions, custom-domains, workspaces, form-versions, notifications, favorites, billing, uploads, public-*, visit-end beacon) and the dynamic preview-form schema to valibot Standard Schema (works directly in createServerFn().inputValidator and TanStack Form validators). AI-SDK-bound schemas (ops-schema.ts, form-generate.ts) deliberately stay on zod: AI SDK v6 builds JSON Schema via schema['~standard'].jsonSchema, which valibot 1.4.0 does not expose, so streamObject/tool/useObject would throw at runtime. The only stable valibot adapter (@ai-sdk/valibot) is 3.0.0-canary.
…remove zod ops-schema.ts + form-generate.ts now use valibot; schemas passed to AI SDK (streamObject/tool/useObject) are wrapped with valibotSchema() from @ai-sdk/valibot@2.0.28 (ai-v6 line, deps the provider-utils@4.0.27 we already have), which supplies the JSON Schema the SDK sends to the model via @valibot/to-json-schema. Verified the conversion produces valid JSON Schema for formGenSchema/freeThemeSchema/themeTokensSchema at runtime. zod is fully removed from source and from our direct deps (remains only as a transitive dep of the AI SDK packages). Completes the zod->valibot migration.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Migrates validation from zod → valibot across the entire app. zod was the single largest dependency in the public-form client bundle, and valibot's modular/tree-shakeable Standard Schema plugs directly into TanStack Router
validateSearch, StartcreateServerFn().inputValidator, TanStack DB collection schemas, and TanStack Form — no adapter needed.Result — public-form
indexchunkzod is fully removed from the public-form critical path and from our direct dependencies (it remains only as a transitive dep of the AI SDK packages, in the lazy editor chunk).
Scope
$shortId,$slug,f/$formId,login,login/email, form-builderedit):zodValidator→ valibot Standard Schema invalidateSearch. Dropped@tanstack/zod-adapter.src/lib/valibot-search.ts): verified zod-parity helpers forcoerce/.default/.catch.collections/local/form.ts): TanStack DB schema.inputValidators + dynamic preview-form schema.ops-schema.ts,form-generate.ts): valibot, wrapped withvalibotSchema()from@ai-sdk/valibot@2.0.28(ai-v6 line; deps the@ai-sdk/provider-utils@4.0.27we already use) so the AI SDK gets JSON Schema via@valibot/to-json-schema. Raw valibot can't be passed to the AI SDK (its~standardlacksjsonSchema);valibotSchema()is required — conversion verified at runtime.Verification
pnpm exec tsc --noEmit: 0 errorspnpm exec vitest run --no-file-parallelism: 422/422 pass (also green in pre-push)Deps
valibot@1.4.0,@ai-sdk/valibot@2.0.28,@valibot/to-json-schema@1.7.0zod,@tanstack/zod-adapter