Skip to content

fix(zod): unify fieldMeta storage; portable hello-world example#181

Merged
ozzyfromspace merged 2 commits intomainfrom
claude/zod-v3-v4-cleanup
May 8, 2026
Merged

fix(zod): unify fieldMeta storage; portable hello-world example#181
ozzyfromspace merged 2 commits intomainfrom
claude/zod-v3-v4-cleanup

Conversation

@ozzyfromspace
Copy link
Copy Markdown
Contributor

Summary

  • A bare-Vue + Zod 3 consumer importing 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's field-meta.ts calling z.registry() at module top level, which left a z.registry namespace reference statically reachable from the unified entry's module graph.
  • Lifts field-metadata storage into a shared core (src/runtime/core/field-meta-store.ts) — pure WeakMap-backed, no zod runtime 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.
  • The native v4 chain schema.register(fieldMeta, payload) keeps working — Zod 4's .register() only calls .add(this, payload) structurally, satisfied by the shared store.
  • Unified withMeta runtime-branches on schema shape: Zod 4 schemas clone via .clone(), Zod 3 schemas via new Ctor(_def). Same end result, both write to the same WeakMap.
  • Switches the hello-world example from z.email() (v4-only standalone) to z.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 unified useForm JSDoc — explicit attaform/zod-v4 docs untouched.

Test plan

  • pnpm typecheck clean
  • pnpm test — 2088 passing, including the new test/core/field-meta-store.test.ts that exercises cross-major round-trips through the unified entry
  • pnpm lint clean
  • pnpm check:size — every entry within budget; dist/zod.mjs essentially unchanged at 40.58 KB
  • pnpm check:bench — every scenario inside the 3× floor
  • grep z.registry|z.email dist/ returns no matches — the v4-only references are no longer reachable from attaform/zod's module graph
  • Manual repro: build a tiny v3 + bare-Vue consumer of attaform/zod and confirm the IMPORT_IS_UNDEFINED warning no longer fires

🤖 Generated with Claude Code

ozzyfromspace and others added 2 commits May 8, 2026 19:31
…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>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
attaform Ready Ready Preview, Comment May 8, 2026 11:36pm

@ozzyfromspace ozzyfromspace merged commit 72d8d65 into main May 8, 2026
12 checks passed
@ozzyfromspace ozzyfromspace deleted the claude/zod-v3-v4-cleanup branch May 8, 2026 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant