Repository navigation
Share one lazily loaded zod across plugin frontends - #6959
Merged
Merged
Conversation
Twelve bundled plugin frontends each carried their own 187 KB raw copy of zod, about 540 KB brotli per cold load. zod was kept out of the shared plugin runtime because exposing its namespace from the boot chunk stopped tree-shaking and grew boot by 33 KB brotli. Plugin app builds now shim `zod` to a `zod` runtime slot when the plugin's installed zod has the host's major version and is no newer than it. Other plugins keep bundling their own copy. The host provides the slot as a lazy runtime group, like Pierre. vite-plugin-zod-runtime.ts builds that group from separate module ids, so the slot's full namespace never touches the boot chunk's zod. It also stubs locales the way plugin builds do. Cold load of `/` on a scrubbed production subset, 100 ms latency: transfer 2706 -> 2287 KB. At 5 Mbps over HTTP/2 the load settles 5492 -> 4851 ms. First content is unchanged, and boot grows 0.4 KB. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A bundle from `bb plugin build` (npm plugins must ship one) expected the host to provide the shared zod. Older bb versions don't, and their only artifact check is the SDK major, so that frontend would fail to load there. buildPluginApp now takes hostProvidedZod. Builds the bb server makes itself (bundled, git and local plugins, and source rebuilds) pass true. The CLI's `bb plugin build` and `bb plugin dev` keep zod bundled. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
force-pushed
the
bb/plugin-shared-zod
branch
from
November 3, 2026 23:35
0cb2368 to
c4273ba
Compare
This was referenced Nov 23, 2026
ymichael
pushed a commit
that referenced
this pull request
Nov 24, 2026
## Human comments ## What was wrong Five Ladle stories called `installTestPluginRuntime()` at module load (`.ladle/workflows.stories.tsx` through `loadPluginApp`, which calls it). That call replaces the plugin runtime that Ladle's global provider installs (`.ladle/plugin-runtime.ts`) with the fake test SDK. The stories mount plugins through core hosts, not through `renderSlot`, so the fake `useBbContext()` and `useBbNavigate()` throw. The call had no effect until #6942 removed Ladle's static `@get-bb/plugin-sdk/app` shim. Since then, plugins read the global runtime. Because Ladle changes stories without a reload, one of these stories also broke every later story in the same tab. In the same pass, `ladle build` failed on `virtual:bb-plugin-zod`, because #6959 added `pluginZodRuntime()` to the app and Vitest configs but not to `.ladle/vite.config.ts`. See #8060. ## What changed - `PluginThreadList.stories.tsx`, `AskUserQuestionPlugin.stories.tsx`, `CodexMcpElicitation.stories.tsx`, `InteractionStates.stories.tsx`: remove `installTestPluginRuntime()`. - `.ladle/workflows.stories.tsx`: collect registrations with core's `collectPluginAppRegistrations` instead of `loadPluginApp`. - New `PluginThreadList.stories.test.tsx`: renders the Action alignment story with Ladle's runtime and waits for a thread row. It also fails if any `*.stories.tsx` imports `@get-bb/plugin-sdk/testing/app`. - `.ladle/vite.config.ts`: add `pluginZodRuntime()` (separate commit). ## How you verified - The new tests fail on the original stories (the render test fails with `useBbContext() needs the test slot environment`, and the guard lists all five files). They pass with this change. - `apps/app/.ladle/tests/sidebar-actions.mjs` (Chromium, Playwright 1.58.2): on main it times out waiting for `thr_actions_leaf_short`. With this change it prints `PASS: parent and leaf actions align at 220, 288 and 360px; disclosure precedes quick actions and overflow` on `ladle serve` and on a served `ladle build`. - Nine affected stories (thread list x2, question form, Codex form and computer use, Additional States x3, Workflows panel) render with no page errors. - `npx ladle build` in `apps/app`: fails on main with `Rollup failed to resolve import "virtual:bb-plugin-zod"`, succeeds with this change. - `pnpm exec turbo run typecheck lint lint:type-aware test --filter=@bb/app`: pass. One test, `UpdatePluginDialog.test.tsx`, fails only under an `en_AU` host locale and passes with `en_US`. It is not related to this change. Fixes #8060 > AGENT GENERATED
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.
Human comments
What was wrong
Twelve bundled plugin frontends each bundled their own copy of zod: 187 KB raw, about 45 KB brotli each, and about 540 KB brotli on every cold load. That was a fifth of everything a cold load transferred, measured in the cold-load investigation (thr_epbrhxq39i). zod had been kept out of the shared plugin runtime on purpose.
runtime-shims.mjsrecords that exposing its namespace from the host stopped the boot chunk from tree-shaking zod and grew boot by 33 KB brotli.What changed
packages/plugin-build):VERSIONED_RUNTIME_SLOT_BY_SPECIFIERadds azodslot, behind a newbuildPluginAppoption,hostProvidedZod. Builds the bb server makes itself pass true: bundled, git and local plugins, and source rebuilds. The CLI'sbb plugin buildandbb plugin devkeep zod bundled. A published npm artifact therefore still runs on older bb versions, which would not provide the slot and check only the SDK major. When enabled, a build shimszodto the slot only when the zod installed for that import has the host's major version and is no newer than the host's copy. The host's version is emitted asRUNTIME_PACKAGE_VERSIONSby the export-manifest generator. Otherwise zod still bundles from the plugin'snode_modules, so a plugin pinned to zod 3 or a newer zod 4 keeps working.zod/miniand server builds are unchanged. The slot is kept out ofRUNTIME_SLOT_BY_SPECIFIER, so it doesn't become a scaffold type-only devDependency, and the server's default slot list for bundles without metadata doesn't load zod for old bundles.apps/app): thezodslot is a lazy runtime group, like Pierre. It is loaded in parallel with the first plugin bundle that declares it.vite-plugin-zod-runtime.tsresolvesvirtual:bb-plugin-zodto a copy of zod under separate module ids, so the slot's full namespace never pins the boot chunk's tree-shaken zod. It stubs zod's locale barrel toen, as plugin builds already do. In dev and tests the id resolves to the normal zod.docs/ui-code-splitting.md(lazy runtime groups) and the plugin-authoring reference (frontend-hooks-and-ui.md) describe whenzodis shared.There are no server/daemon wire changes and no Plugin SDK surface change.
How you verified
Bytes, from production builds of this branch and its base
7fa7f46fad:app.jsfilesapp.jsCold loads in Chromium on a scrubbed subset of production data (4,387 threads): production build, fresh context per load, 100 ms latency. The two builds were benchmarked in alternating server restarts. Medians of 5 runs per side at 20 Mbps and 3 at 5 Mbps:
/transfer/settled, HTTP/2, 5 Mbps/sidebar, HTTP/2, 5 Mbps/sidebar, HTTP/2, 20 Mbps/sidebar, HTTP/1.1, 20 MbpsFirst-content times are within noise at both bandwidths. The win is bytes and settle time on slow links. One request is added (
plugin-zod-runtime-*.js). Loading/, a thread and/settings/pluginsgave no plugin load warnings or new console errors. Ten enabled plugins report thezodslot, and the shared chunk is requested once.packages/plugin-build/src/build-plugin-app.test.ts: the version gate (same, older, newer, other major, prerelease), and builds against a fake installed zod. A compatible version is shimmed only whenhostProvidedZodis set; a newer minor, the next major, or a CLI build bundles the plugin's own copy.apps/app/src/vite-plugin-zod-runtime.test.ts: builds a fixture whose entry imports one zod export and lazily imports the slot. The lazy chunk holds only the separate copy, the entry holds no zod code outside its import, and locales are stubbed. Resolving the copy's imports to the shared ids makes it fail.pnpm exec turbo run typecheck lint --filter=@bb/app --filter=@bb/plugin-build, the two test files, the bundle budget check afterpnpm exec turbo run build --filter=@bb/app --filter=@bb/bundled-plugins. CI runs the full suites.🤖 Generated with Claude Code