Skip to content

v0.17.0

Latest

Choose a tag to compare

@mertcanaltin mertcanaltin released this 15 Nov 11:46
· 13 commits to main since this release
df6b5a8

A form that validates with react-hook-form and zod can ship without zod, with nothing in the form changed; ataResolver forms ship without the ata runtime again; and a Next.js build applies the plugin's size choices to what the browser gets.

react-hook-form

  • zodResolver(schema) from @hookform/resolvers/zod is compiled away where the build can read the schema: a constant of the file, at the top or inside the component, a schema written in the call, or one imported by name from another module of the project. The build runs the schema with the application's own zod, writes a check with the same verdict, and records the issue zod reports for each rule, a custom message included, by asking zod. Before a call is replaced, the build holds the written resolver to zod on documents made for that form; a form that differs keeps its call. On a Next.js 16.4.6 page with a five-field form, the scripts the page loads beyond the home page went from 43,450 to 15,411 bytes gzipped under Turbopack and from 37,288 to 15,928 under webpack. In a Vite 7 + React 19 app with the same form, all of the page's JavaScript went from 108,338 to 85,683 bytes gzipped (82,425 with react-hook-form and no validation at all). Carried: strings with their checks and formats, z.email() and the like, url(), trim/toLowerCase/toUpperCase, numbers with int, bounds and z.coerce.number(), booleans, enums, literals, optional fields, nested objects, arrays, and refine whose function reads only its argument. Everything else keeps its call and zod. On by default; zodResolver: false turns it off. An application that sets zod's locale or a global error map gets nothing replaced.
  • ataResolver(schema) is compiled away again. The rewrite waited on ataCompiledResolver in @hookform/resolvers, which was declined upstream, so it never ran; the build now writes the resolver itself. Same page: 81,689 to 14,269 bytes under Turbopack.
  • npx @ata-project/unplugin scan says which zodResolver, ataResolver and new Validator calls a build would compile, and for each of the others why not, naming the field and the cause. Nothing is written. A build prints the same lines.

Fixes

  • compile() holds each validators file it writes from zod, valibot or TypeBox modules against that library before writing it: documents made from each export (valid ones, ones with one rule broken, both sides of every bound; 50 an export, or verify: <number>) go to the library's own check and to the written validator, and a difference throws with the document. Three things the JSON Schema does not say are now refused by export and path: a check written after trim(), toLowerCase(), toUpperCase() or normalize(), z.coerce.number(), and .catch(value). Up to 0.15.0 these were converted without a word, and the page answered differently from zod on those values. compile({ ..., check: true }) writes nothing and returns the files a compile would change, for a CI step. On 17 schemas of 41 fields the check added about 30 ms to a 140 ms compile; verify: false skips it. (This was released on main as 0.16.0 but never published to npm, so it ships here.)
  • Under webpack and Rspack (so next build --webpack), a file could be transformed before the build's table and sharedErrors choices were made, and was then written as if neither existed; in Next.js that was every client file. A six-form page: 8,719 to 5,554 bytes.
  • sharedErrors: 'auto' with ir: false wrote compact modules that made a bundle 4 to 8 KB larger for schemas of middling size: the bar was set when ata's error runtime was smaller. It is set from real bundles again, and a test holds it there.
  • verify checked nothing on the IR path, the default since ata-validator 1.63.1. It now holds the IR's modules to the runtime. With ata-validator 1.63.x it reports real differences on some schemas (references to the official meta-schemas, among others) that 1.64.0 fixes; use it with 1.64.0.
  • The imports a rewrite adds go after a file's directives, so 'use client' stays first (Next.js failed the build of a client component holding its own new Validator).
  • table and sharedErrors in their 'auto' form decide for what a page loads together, not for the whole project.

Smaller pages

  • smallFormats: 'auto': a module written for a browser checks email, uri and uri-reference with ata-validator's smaller regular expressions (needs ata-validator 1.64.0; an older one keeps the scanners).
  • errorFields: 'auto': a validator whose errors are read only through keyword, instancePath, schemaPath, params and message is written with plain errors. A six-field signup form: 4,529 to 2,128 bytes.

Recommended with ata-validator 1.64.0. Tested: 356 tests, 354 pass, 2 skipped, against ata-validator 1.64.0 as packed from its release branch.

Not covered: Rspack and Rollup were not measured in an application for the zod rewrite; zod 3; schemas re-exported through an index file.