fix(zod): unify fieldMeta storage; portable hello-world example#181
Merged
ozzyfromspace merged 2 commits intomainfrom May 8, 2026
Merged
fix(zod): unify fieldMeta storage; portable hello-world example#181ozzyfromspace merged 2 commits intomainfrom
ozzyfromspace merged 2 commits intomainfrom
Conversation
…ference Lifts field-metadata storage from per-adapter WeakMaps into a single shared core store. Every entry — `attaform/zod`, `attaform/zod-v3`, `attaform/zod-v4` — re-exports the same registry-shaped object so a payload registered via any entry is visible at lookup whether the v3 or v4 adapter actually runs. Also fixes a Rollup `IMPORT_IS_UNDEFINED` warning that fired for Zod 3 consumers using `attaform/zod` without the Vite plugin alias: the v4 adapter's field-meta module called `z.registry()` at module top level, leaving the namespace property reachable from `attaform/zod`'s module graph. Lifting storage out of the v4 adapter drops that reference; the native v4 chain `schema.register(fieldMeta, payload)` still works against the shared store structurally (Zod 4's `.register()` only calls `.add(this, payload)` on the registry). The unified entry's `withMeta` runtime-branches on schema shape — Zod 4 schemas clone via the native `.clone()`, Zod 3 schemas reconstruct via constructor + `_def`. Both write to the same WeakMap, so cross-major visibility is automatic. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`z.email()` is a Zod 4 standalone — Zod 3's equivalent is `z.string().email()`. The unified-entry hello-world should compile unchanged on both majors so a v3 user copying the README quickstart doesn't hit `TypeError: z.email is not a function` before they even see a working form. Also updates the labels-and-placeholders quickstart section to `withMeta()` (cross-major) instead of the v4-only `schema.register(fieldMeta, ...)` chain. Touches: README, /docs/quickstart, /docs/api/zod, the unified useForm JSDoc. The explicit `attaform/zod-v4` docs keep `z.email()` — that's where v4-flavored idioms belong. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
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.
Summary
attaform/zod(no Vite plugin) hit a Rollup build warning:[IMPORT_IS_UNDEFINED] Warning: Import 'registry' will always be undefined .... The trigger was the v4 adapter'sfield-meta.tscallingz.registry()at module top level, which left az.registrynamespace reference statically reachable from the unified entry's module graph.src/runtime/core/field-meta-store.ts) — pure WeakMap-backed, nozodruntime import. Every entry (attaform/zod,attaform/zod-v3,attaform/zod-v4) re-exports the same shim so a payload registered through any entry surfaces at lookup whichever adapter dispatches.schema.register(fieldMeta, payload)keeps working — Zod 4's.register()only calls.add(this, payload)structurally, satisfied by the shared store.withMetaruntime-branches on schema shape: Zod 4 schemas clone via.clone(), Zod 3 schemas vianew Ctor(_def). Same end result, both write to the same WeakMap.z.email()(v4-only standalone) toz.string().min(2, ERROR)so a Zod 3 user copying the README quickstart compiles without changes. Touches README, /docs/quickstart, /docs/api/zod, and the unifieduseFormJSDoc — explicitattaform/zod-v4docs untouched.Test plan
pnpm typecheckcleanpnpm test— 2088 passing, including the newtest/core/field-meta-store.test.tsthat exercises cross-major round-trips through the unified entrypnpm lintcleanpnpm check:size— every entry within budget;dist/zod.mjsessentially unchanged at 40.58 KBpnpm check:bench— every scenario inside the 3× floorgrep z.registry|z.email dist/returns no matches — the v4-only references are no longer reachable fromattaform/zod's module graphattaform/zodand confirm theIMPORT_IS_UNDEFINEDwarning no longer fires🤖 Generated with Claude Code