Skip to content

Docgen: Register service runtime, payload argTypes, and bundler guardrails#35108

Open
JReinhold wants to merge 8 commits into
nextfrom
split/docgen-service-plumbing
Open

Docgen: Register service runtime, payload argTypes, and bundler guardrails#35108
JReinhold wants to merge 8 commits into
nextfrom
split/docgen-service-plumbing

Conversation

@JReinhold

@JReinhold JReinhold commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Closes #

What I did

Wires the core/docgen open service for preview and manager registration (behind features.experimentalDocgenServer), adds renderer-converted argTypes to the docgen payload at write time, and skips preview __docgenInfo injection in React Vite/Webpack when the flag is on.

Does not enable experimentalDocgenServer in any config. Does not include docs/manager UI consumption (follow-up PR #35109).

Recommended merge order: after #35106 (open-service load routing). #35107 (RCM subcomponents) improves subcomponent argTypes in the payload but is not required to compile.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

Caution

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

No manual QA without enabling experimentalDocgenServer. Unit tests cover buildDocgenPayload argTypes conversion.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Declare whether manual QA will be needed for this PR during the next release, through qa:needed or qa:skip

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Made with Cursor

Summary by CodeRabbit

  • New Features

    • Experimental docgen server for richer component documentation
    • Automatic extraction and inclusion of argTypes for components and subcomponents
    • Feature flag to enable/disable the docgen functionality
  • Refactor

    • Updated manager/annotation/preset registrations to surface docgen capabilities in the UI
  • Tests

    • Enhanced unit tests to validate argTypes generation and payloads

…rails

Wire preview/manager registration behind experimentalDocgenServer, add renderer-
converted argTypes to the docgen payload, and skip preview __docgenInfo injection
when the flag is enabled. Does not enable the flag by default.

Co-authored-by: Cursor <cursoragent@cursor.com>
@JReinhold JReinhold added feature request ci:normal Run our default set of CI jobs (choose this for most PRs). labels Jun 9, 2026
@JReinhold JReinhold added qa:skip Pull Requests that do not need any QA. core labels Jun 9, 2026
@storybook-app-bot

storybook-app-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

Package Benchmarks

Commit: b6430f2, ran on 11 June 2026 at 19:21:41 UTC

The following packages have significant changes to their size or dependencies:

@storybook/builder-webpack5

Before After Difference
Dependency count 184 184 0
Self size 79 KB 79 KB 🎉 -48 B 🎉
Dependency size 33.98 MB 34.02 MB 🚨 +45 KB 🚨
Bundle Size Analyzer Link Link

storybook

Before After Difference
Dependency count 72 72 0
Self size 20.74 MB 20.86 MB 🚨 +121 KB 🚨
Dependency size 36.12 MB 36.12 MB 0 B
Bundle Size Analyzer Link Link

@storybook/angular

Before After Difference
Dependency count 185 185 0
Self size 160 KB 160 KB 🚨 +54 B 🚨
Dependency size 31.32 MB 31.35 MB 🚨 +32 KB 🚨
Bundle Size Analyzer Link Link

@storybook/ember

Before After Difference
Dependency count 189 189 0
Self size 15 KB 15 KB 🎉 -18 B 🎉
Dependency size 30.80 MB 30.84 MB 🚨 +45 KB 🚨
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 534 534 0
Self size 662 KB 662 KB 0 B
Dependency size 62.16 MB 62.21 MB 🚨 +46 KB 🚨
Bundle Size Analyzer Link Link

@storybook/react-webpack5

Before After Difference
Dependency count 271 271 0
Self size 23 KB 23 KB 0 B
Dependency size 46.70 MB 46.74 MB 🚨 +46 KB 🚨
Bundle Size Analyzer Link Link

@storybook/server-webpack5

Before After Difference
Dependency count 196 196 0
Self size 16 KB 16 KB 0 B
Dependency size 35.24 MB 35.29 MB 🚨 +45 KB 🚨
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 203 203 0
Self size 948 KB 948 KB 0 B
Dependency size 88.99 MB 89.11 MB 🚨 +123 KB 🚨
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 196 196 0
Self size 32 KB 32 KB 0 B
Dependency size 87.48 MB 87.60 MB 🚨 +123 KB 🚨
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 73 73 0
Self size 1.08 MB 1.08 MB 🚨 +132 B 🚨
Dependency size 56.85 MB 56.97 MB 🚨 +121 KB 🚨
Bundle Size Analyzer node node

@storybook/preset-react-webpack

Before After Difference
Dependency count 164 164 0
Self size 18 KB 18 KB 🎉 -24 B 🎉
Dependency size 32.48 MB 32.53 MB 🚨 +44 KB 🚨
Bundle Size Analyzer Link Link

@JReinhold JReinhold marked this pull request as ready for review June 10, 2026 09:39
@JReinhold JReinhold mentioned this pull request Jun 10, 2026
54 tasks
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1301aca6-7afc-42b4-bdde-f90fe33200d4

📥 Commits

Reviewing files that changed from the base of the PR and between 927cb8b and d052c4f.

📒 Files selected for processing (2)
  • code/renderers/react/src/componentManifest/componentMeta/ComponentMetaProject.storyExtraction.test.ts
  • code/renderers/react/src/componentManifest/componentMeta/componentMetaExtractor.ts

📝 Walkthrough

Walkthrough

This PR extends the experimental docgen open-service to support optional argTypes derived from React component metadata. It adds feature-flag-gated manager and preview addon registration, augments the React renderer's buildDocgenPayload to extract and inject argTypes, and conditionally disables legacy docgen plugins in framework presets when the experimental service is active.

Changes

Docgen service with argTypes support

Layer / File(s) Summary
Docgen service contract and schema
code/core/src/shared/open-service/services/docgen/types.ts, code/core/src/shared/open-service/services/docgen/definition.ts, code/core/src/shared/open-service/index.ts
DocgenPayload and DocgenSubcomponent now include optional argTypes?: StrictArgTypes. Service definition adds runtime validation for the new field, makes DocgenServiceState internal, simplifies the query handler, and re-exports service types from the open-service entrypoint.
Manager and preview addon registration
code/core/src/shared/open-service/services/docgen/manager.tsx, code/core/src/shared/open-service/services/docgen/preview.ts, code/core/src/core-server/presets/common-manager.ts, code/core/src/csf/core-annotations.ts
Manager and preview addons conditionally register the docgen service when globalThis.FEATURES?.experimentalDocgenServer is enabled. Docgen annotations are integrated into the core annotations pipeline, and the manager addon is added to the common manager exports list.
React renderer argTypes extraction and tests
code/renderers/react/src/docgen/buildDocgen.ts, code/renderers/react/src/docgen/buildDocgen.test.ts, code/renderers/react/src/componentManifest/componentMeta/componentMetaExtractor.ts, code/renderers/react/src/componentManifest/componentMeta/ComponentMetaProject.storyExtraction.test.ts
Helper functions extract StrictArgTypes from React ComponentDoc and inject computed argTypes into the main payload and subcomponents. Tests and component meta serialization updated to validate argTypes extraction and collapse boolean-literal unions into boolean.
Framework bundling controls for experimental service
code/frameworks/react-vite/src/preset.ts, code/presets/react-webpack/src/framework-preset-react-docs.ts
React Vite and React Webpack presets now check for experimentalDocgenServer and skip legacy docgen plugin injection when enabled, returning the config early to prevent bundling overhead.
Build system module resolution aliases
code/core/scripts/generate-source-files.ts, scripts/build/utils/generate-bundle.ts
Adds esbuild alias mappings for storybook/open-service to the local source path in manager exports generation and runtime bundle configuration.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • storybookjs/storybook#34954: The main PR’s docgen open-service changes (e.g., updates to core/src/shared/open-service/services/docgen/definition.ts and related docgen export wiring/state/query behavior) directly overlap with the retrieved PR’s same core/docgen open-service scaffolding and registration work.
  • storybookjs/storybook#35063: Both PRs modify the experimental docgen open-service contract (e.g., code/core/src/shared/open-service/services/docgen/definition.ts and types.ts), which is the data model consumed by the ref-based components.json manifest generation in the retrieved PR.
  • storybookjs/storybook#34963: Both PRs change the core React→DocgenService pipeline by updating DocgenPayload/docgen provider inputs and React buildDocgen to map extracted component-meta into the service payload (with the main PR specifically extending that payload to include argTypes).
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
code/core/src/core-server/presets/common-manager.ts (1)

14-14: 💤 Low value

Consider documenting the placement rationale.

docgenManager is placed first in the registration array, which the comments indicate affects panel and tool order. While the manager addon currently only registers a service (no UI panels in this PR per the summary), this placement could affect ordering when the UI is added. Since this is experimental and feature-flagged, the impact is limited, but documenting why it's first would help future maintainers.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@code/core/src/core-server/presets/common-manager.ts` at line 14, Add a short
comment explaining why docgenManager is intentionally placed first in the
registration array: note that registration order influences panel and tool
ordering, that docgenManager currently only registers a service (no UI in this
PR), and that it’s experimental/feature-flagged so placement is deliberate to
reserve first position for future UI additions; place this comment immediately
above the array containing docgenManager to make the rationale clear to future
maintainers.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@code/core/src/core-server/presets/common-manager.ts`:
- Line 14: Add a short comment explaining why docgenManager is intentionally
placed first in the registration array: note that registration order influences
panel and tool ordering, that docgenManager currently only registers a service
(no UI in this PR), and that it’s experimental/feature-flagged so placement is
deliberate to reserve first position for future UI additions; place this comment
immediately above the array containing docgenManager to make the rationale clear
to future maintainers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7eb2aa46-6278-4b64-a1d0-29302858a4f7

📥 Commits

Reviewing files that changed from the base of the PR and between 514a19b and 6ca97fd.

📒 Files selected for processing (13)
  • code/core/scripts/generate-source-files.ts
  • code/core/src/core-server/presets/common-manager.ts
  • code/core/src/csf/core-annotations.ts
  • code/core/src/shared/open-service/index.ts
  • code/core/src/shared/open-service/services/docgen/definition.ts
  • code/core/src/shared/open-service/services/docgen/manager.tsx
  • code/core/src/shared/open-service/services/docgen/preview.ts
  • code/core/src/shared/open-service/services/docgen/types.ts
  • code/frameworks/react-vite/src/preset.ts
  • code/presets/react-webpack/src/framework-preset-react-docs.ts
  • code/renderers/react/src/docgen/buildDocgen.test.ts
  • code/renderers/react/src/docgen/buildDocgen.ts
  • scripts/build/utils/generate-bundle.ts

JReinhold and others added 4 commits June 10, 2026 12:48
The instance-type alias was declared twice (before and after docgenServiceDef),
causing TS2300 duplicate identifier in the production dts build. Keep the
declaration after the service def, matching ModuleGraphService.

Co-authored-by: Cursor <cursoragent@cursor.com>
TypeScript models `boolean` as `true | false`, so an optional boolean prop
(`true | false | undefined`) fell through serializeType to `typeToString` as
`boolean | undefined`, which downstream argType mapping treated as `other`.
Collapse the boolean-literal pair back to `boolean`, and update the RCM
extraction snapshots that captured the old output.

Co-authored-by: Cursor <cursoragent@cursor.com>
Disabling react-docgen __docgenInfo injection when experimentalDocgenServer is
on belongs with the docs-block service consumption (it's the other half of the
same swap). Without the consumer, dropping injection regresses argTypes and
descriptions in any Storybook with the flag enabled (including our internal one).
Move both preset early-returns to the UI consumption PR.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:normal Run our default set of CI jobs (choose this for most PRs). core feature request qa:skip Pull Requests that do not need any QA.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants