Skip to content

fix: allow tree shaking unused Zod locales in browser bundles - #843

Merged
idosal merged 1 commit into
modelcontextprotocol:mainfrom
krubenok:fix/browser-bundle-tree-shaking
Nov 25, 2026
Merged

idosal merged 1 commit into
modelcontextprotocol:mainfrom
krubenok:fix/browser-bundle-tree-shaking

Conversation

@krubenok

@krubenok krubenok commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Import Zod's config directly in App instead of accessing the exported z object.
  • Generate schemas with import * as z from "zod/v4" so consumer bundlers can prune unused exports, including locales.
  • Add regression tests for the App, AppBridge, and React entries using the SDK's Bun bundling step followed by an esbuild browser bundle. Assert retained locale modules by positive output-byte contributions, not merely parsed inputs.

No dependency, validation, JIT configuration, or locale-selection behavior changes. Consumers can still explicitly import and configure other locales.

Relates to #665 and #649.

Bundle measurements

Built from upstream main cf599cc4 using MCP core/client 2.0.0, Zod 4.6.6, and esbuild 0.25.12. Browser ESM, ES2020, minified, no code splitting; gzip level 9. Measurements use the regular SDK entries, not *-with-deps.

Entry Minified bytes before → after Gzip-9 bytes before → after
App 604,931 → 254,928 130,821 → 67,777
AppBridge 599,496 → 249,499 128,360 → 65,319
React 613,971 → 263,949 134,051 → 70,945

Each probe retains 1 English locale module instead of 64 locale modules. The App probe instantiates App and calls connect(); the AppBridge and React probes retain AppBridge and useApp, respectively.

Validation

  • npm run build
  • npm test — 454 passed, 3 skipped
  • npm run prettier
  • npm exec typedoc -- --treatValidationWarningsAsErrors --emit none
  • The 3 new bundle regression tests fail with the original imports and pass with this change.
  • Opus 5.5 self-review found no unresolved high-confidence issues.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the changes aimed at reducing unused Zod locale bundle overhead.

No open issues 🎉

What changed in this PR

This PR addresses unused Zod locale bundle overhead reported in #665 and #649 by making SDK imports easier for consumer bundlers to tree-shake, without changing validation, JIT configuration, or locale selection.

Changes:

  • Import Zod’s config directly in App.
  • Use namespace imports in generated schemas and preserve them during regeneration.
  • Add browser-bundle regression tests for App, AppBridge, and React that verify only the English locale contributes output bytes.
File Description
src/​generated/​schema.ts Uses a Zod namespace import to enable tree shaking.
src/​bundle.test.ts Tests retained locales after Bun and esbuild bundling.
src/​app.ts Calls directly imported config while preserving JIT settings.
scripts/​generate-schemas.ts Generates and documents the tree-shakeable import form.

Review effort: Balanced

@idosal idosal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @krubenok !

@idosal
idosal merged commit 87bcdc8 into modelcontextprotocol:main Nov 25, 2026
@krubenok
krubenok deleted the fix/browser-bundle-tree-shaking branch November 25, 2026 22:12
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.

3 participants