Repository navigation
fix: import zod as a namespace so bundlers can tree-shake it - #291
Merged
benbrandt merged 1 commit intoOct 19, 2026
Merged
Conversation
schema-deserialize.ts was the only shipped source file importing the named `z` export from "zod/v4". That export is itself a namespace object re-exported by name, which esbuild cannot tree-shake, so consumers bundling the SDK with esbuild received every zod locale (about 264 KB minified). The generated schema files already use `import * as z from "zod/v4"`; this matches them. No behavior change: both forms expose the same bindings.
benbrandt
approved these changes
Oct 19, 2026
benbrandt
left a comment
Member
There was a problem hiding this comment.
Thank you for doing all of this testing! I'm sure there is more that we can improve, but this is already a big win! ❤️
benbrandt
enabled auto-merge (squash)
October 19, 2026 12:11
7 tasks done
This was referenced Oct 19, 2026
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
src/schema-deserialize.tsimports zod withimport { z } from "zod/v4". In zod, that namedzis a namespace object re-exported by name (zod/v4/classic/index.js:import * as z from "./external.js"; export { z }). esbuild cannot tell which members of a namespace reached that way are used, so it keeps everything the namespace references, includinglocales. Consumers who bundle the SDK with esbuild therefore ship all 48 zod locales, even though only English is used.import * as z from "zod/v4", the formscripts/generate.jsalready emits for every generated schema file and the form zod's docs use.z.unknown,z.preprocess,z.array,z.NEVER, and the types).Measurement
A minimal consumer (
import { ClientSideConnection } from "./dist/acp.js") bundled with esbuild 0.28.2 (--bundle --minify --platform=node --format=esm):Both bundles load and run.
Validation
npm run generate:check,lint,format:check,build,test(976 tests passed), anddocs:ts:verifypassed.typoswas run locally viauvx typos --config ./typos.toml.git diff --checkpassed.No tests or documentation were added, per repository instructions.