feat: Upgrade to Storybook 10 with MCP addon support#3839
feat: Upgrade to Storybook 10 with MCP addon support#3839lichliter wants to merge 2 commits intoWorkday:prerelease/majorfrom
Conversation
Migrate from Yarn Classic to Yarn 4 (nodeLinker: node-modules) and upgrade Storybook 8.4.7 to 10.3.3. Add @storybook/addon-mcp for AI agent component development, docs, and testing. Storybook config changes: - Restructure .storybook/main.ts for SB10's ESM-only config loader - Add Vite resolve aliases for workspace package subpath resolution - Add exports fields to workspace packages for ESM compatibility - ESM-ify imports in .storybook/ plugin files (explicit extensions, process.cwd(), JSON import assertions) Re-integrate all custom Vite plugins via viteFinal: - vitePluginWholeSource (Show Code / StackBlitz) - vitePluginRedirectMDXToGithub (MDX link rewriting) - vitePluginInlineSpecifications (spec table pre-parsing) - vitePluginTypescriptWithTransformers (style transform + docgen) Patch 5 @emotion/* packages to add exports fields for Node ESM resolution of @emotion/css/create-instance and transitive deps. SB10's ESM-strict loader can't resolve the directory-style subpath without explicit exports maps. Patches can be removed when Emotion ships native exports support. The styling config inlines a simplified version that excludes handleFocusRing (which would cascade into @workday/canvas-kit-react directory subpath resolution). focusRing() calls fall back to runtime Emotion — functionally identical, just not statically compiled. Made-with: Cursor
69a442e to
c7c8ae8
Compare
Storybook's built-in manifest generator produces stub snippets like `const Basic = () => <Tabs />;` because getCodeSnippet cannot follow cross-file imports. This makes the MCP addon's documentation tools useless for AI consumers. Fix by attaching an experimental_manifests hook on the config object that post-processes the manifest: for each story with a `render:` pointing to an imported example, read the actual example file and replace the stub snippet with its full source. Also add tsconfig paths mapping workspace packages to source files so the manifest's react-docgen-typescript pipeline resolves component imports to source instead of node_modules (which it rejects). Tradeoff: react-docgen-typescript uses the full TypeScript compiler and adds ~30-60s to Storybook startup. This is acceptable for hosted deployments but can be reverted to `reactDocgen: false` for local dev if needed. Made-with: Cursor
PR Review — Skeptical Maintainer PerspectiveOverall impressionThis PR bundles three distinct migrations into a single changeset: Storybook 8 → 10, Yarn Classic → Yarn 4, and the new MCP addon integration. Each of these is a non-trivial infrastructure change with its own risk profile. I'd strongly prefer to see these broken into separate PRs (Yarn 4 first, then SB10, then MCP addon) so we can bisect regressions and review each migration on its own terms. As a single PR, the blast radius is enormous and the review burden is disproportionately high. That said, here are my specific concerns: 1.
|
Summary
Upgrade Storybook 8.4.7 → 10.3.3, migrate Yarn Classic → Yarn 4, and add
@storybook/addon-mcpfor AI-agent-friendly component documentation.Storybook 10 + Yarn 4
nodeLinker: node-modules.storybook/main.tsfor SB10's ESM loader (explicit.tsextensions, JSON import assertions,process.cwd()paths)exportsfields to workspace packages for ESM compatibilityresolve.aliasentries for workspace package subpath resolutionRe-integrated Vite plugins (via
viteFinal)All custom plugins restored in
.storybook/main.ts:vitePluginWholeSource— Show Code / StackBlitz raw source injectionvitePluginRedirectMDXToGithub— MDX link rewritingvitePluginInlineSpecifications— spec table pre-parsingvitePluginTypescriptWithTransformers— style transform + docgen pipelineEmotion ESM patches
Patch 5
@emotion/*packages (css,cache,sheet,weak-memoize,memoize) to addexportsfields for Node ESM resolution. Required because SB10's ESM-strict loader can't resolve@emotion/css/create-instancewithout explicit exports maps. Patches can be removed when Emotion ships nativeexportssupport.MCP manifest enrichment
The
@storybook/addon-mcpserves documentation from/manifests/components.json, but Storybook's built-ingetCodeSnippetonly does single-file AST analysis — it can't followrender: ImportedFnacross files, producing stubs likeconst Basic = () => <Tabs />;.Fix: An
experimental_manifestshook on the config object post-processes the manifest — for each story with an imported render function, it reads the actual example file and replaces the stub snippet with its full source (imports, JSX, hooks, etc.).Props: Added
tsconfig.jsonpaths mapping@workday/canvas-kit-*to source files so the manifest'sreact-docgen-typescriptpipeline resolves components to source instead ofnode_modules. This extracts real prop tables (e.g. 87 props for Tabs).Tradeoff:
react-docgen-typescriptuses the full TypeScript compiler and adds ~30-60s to startup. Acceptable for hosted deployments; can be reverted toreactDocgen: falsefor local dev.Known limitations
handleFocusRingexcluded from styling config — importing it pulls in@workday/canvas-kit-react/commonwhich uses directory subpath exports that Node ESM can't resolve.focusRing()falls back to runtime Emotion (functionally identical, just not statically compiled).Release Category
Test plan
yarn startboots Storybook without errorsget-documentationfor Tabs showsTabs.List,Tabs.Item,Tabs.Panel)