Skip to content

fix: bundle SDK+zod in react-with-deps (was byte-identical to ./react)#539

Open
ochafik wants to merge 2 commits intomainfrom
worktree-agent-a62a415d
Open

fix: bundle SDK+zod in react-with-deps (was byte-identical to ./react)#539
ochafik wants to merge 2 commits intomainfrom
worktree-agent-a62a415d

Conversation

@ochafik
Copy link
Contributor

@ochafik ochafik commented Mar 6, 2026

Problem

Copy-paste bug from PR #221 (commit e078250a, 2026-01-09). That PR added app-with-deps and react-with-deps as siblings for CDN/import-map no-bundler consumption. But the react-with-deps external array was duplicated from the regular ./react entry without dropping @modelcontextprotocol/sdk — so it never actually bundled anything extra.

Result: react-with-deps.js has shipped byte-identical to react/index.js for 10 releases (v0.3.1 → v1.2.0). Same MD5, same bytes. After #534 (zod externalized via PEER_EXTERNALS), both entries used ["react", "react-dom", ...PEER_EXTERNALS] — still identical.

Fix

Drop ...PEER_EXTERNALS from the react-with-deps external array so it mirrors app-with-deps: bundle @modelcontextprotocol/sdk + zod, keep only React external.

   buildJs("src/react/index.tsx", {
     outdir: "dist/src/react",
-    external: ["react", "react-dom", ...PEER_EXTERNALS],
+    external: ["react", "react-dom"],
     naming: { entry: "react-with-deps.js" },
   }),

React and react-dom MUST stay external — bundling them would cause dual-React-instance hooks errors (Invalid hook call). The consumer provides React via an import map (esm.sh, unpkg, etc.).

Use case

ESM-from-CDN React apps using import maps — no npm, no bundler:

<script type="importmap">
{
  "imports": {
    "react": "https://esm.sh/react@19",
    "react-dom": "https://esm.sh/react-dom@19",
    "react-dom/client": "https://esm.sh/react-dom@19/client"
  }
}
</script>
<script type="module">
  import { useApp } from "https://unpkg.com/@modelcontextprotocol/ext-apps/dist/src/react/react-with-deps.js";
  // SDK + zod bundled — no need to map them
</script>

Verification

index.js (./react) react-with-deps.js
Size 26,153 B 323,420 B
MD5 852ae4b6... fb54392b...
from"@modelcontextprotocol/sdk" 1 (external) 0 (bundled)
from"zod" 1 (external) 0 (bundled)
from"react" 2 (external) 2 (still external ✓)

Module smoke test: node -e "import(...)" → parses cleanly, exports useApp, useAutoResize, useDocumentTheme, useHostStyles, App, PostMessageTransport, all Zod schemas.

Net diff vs main

One line in build.bun.ts. package.json unchanged.

The react-with-deps build entry was introduced in PR #221 (e078250) as a
sibling to app-with-deps for CDN/unpkg no-bundler use. But its external
array was duplicated without editing — it never dropped @modelcontextprotocol/sdk
from externals, so it has shipped byte-identical to ./react for 10 releases
(v0.3.1 → v1.2.0).

After #534 merged, both entries use ['react', 'react-dom', ...PEER_EXTERNALS]
— still identical, just smaller.

Delete rather than fix: React apps always use a bundler; the CDN/unpkg
use case (HTML-string apps like qr-server) doesn't apply to React hooks.
Zero consumers verified (examples/docs/tests/plugins).
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 6, 2026

Open in StackBlitz

@modelcontextprotocol/ext-apps

npm i https://pkg.pr.new/@modelcontextprotocol/ext-apps@539

@modelcontextprotocol/server-basic-preact

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-preact@539

@modelcontextprotocol/server-basic-react

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-react@539

@modelcontextprotocol/server-basic-solid

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-solid@539

@modelcontextprotocol/server-basic-svelte

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-svelte@539

@modelcontextprotocol/server-basic-vanillajs

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-vanillajs@539

@modelcontextprotocol/server-basic-vue

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-vue@539

@modelcontextprotocol/server-budget-allocator

npm i https://pkg.pr.new/@modelcontextprotocol/server-budget-allocator@539

@modelcontextprotocol/server-cohort-heatmap

npm i https://pkg.pr.new/@modelcontextprotocol/server-cohort-heatmap@539

@modelcontextprotocol/server-customer-segmentation

npm i https://pkg.pr.new/@modelcontextprotocol/server-customer-segmentation@539

@modelcontextprotocol/server-debug

npm i https://pkg.pr.new/@modelcontextprotocol/server-debug@539

@modelcontextprotocol/server-map

npm i https://pkg.pr.new/@modelcontextprotocol/server-map@539

@modelcontextprotocol/server-pdf

npm i https://pkg.pr.new/@modelcontextprotocol/server-pdf@539

@modelcontextprotocol/server-scenario-modeler

npm i https://pkg.pr.new/@modelcontextprotocol/server-scenario-modeler@539

@modelcontextprotocol/server-shadertoy

npm i https://pkg.pr.new/@modelcontextprotocol/server-shadertoy@539

@modelcontextprotocol/server-sheet-music

npm i https://pkg.pr.new/@modelcontextprotocol/server-sheet-music@539

@modelcontextprotocol/server-system-monitor

npm i https://pkg.pr.new/@modelcontextprotocol/server-system-monitor@539

@modelcontextprotocol/server-threejs

npm i https://pkg.pr.new/@modelcontextprotocol/server-threejs@539

@modelcontextprotocol/server-transcript

npm i https://pkg.pr.new/@modelcontextprotocol/server-transcript@539

@modelcontextprotocol/server-video-resource

npm i https://pkg.pr.new/@modelcontextprotocol/server-video-resource@539

@modelcontextprotocol/server-wiki-explorer

npm i https://pkg.pr.new/@modelcontextprotocol/server-wiki-explorer@539

commit: 9991467

Reverts the deletion from the previous commit and applies the actual fix.

The react-with-deps external array was copy-pasted in PR #221 without
dropping PEER_EXTERNALS — now it mirrors app-with-deps: bundles
@modelcontextprotocol/sdk + zod for CDN/import-map consumers.

React and react-dom MUST remain external — bundling them would cause
dual-React-instance hooks errors. Consumer provides them via import map.

Before: index.js 26KB == react-with-deps.js 26KB (identical MD5)
After:  index.js 26KB != react-with-deps.js 323KB (SDK+zod bundled)
@ochafik ochafik changed the title chore: remove dead ./react-with-deps export (copy-paste bug from #221) fix: bundle SDK+zod in react-with-deps (was byte-identical to ./react) Mar 6, 2026
@ochafik ochafik marked this pull request as ready for review March 6, 2026 19:40
@ochafik ochafik requested a review from jonathanhefner March 6, 2026 19:40
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