Skip to content

Docgen: Fix inferred argTypes from initial args overriding docgen and custom argTypes in experimentalDocgenServer mode - #35196

Merged
JReinhold merged 4 commits into
nextfrom
jeppe-cursor/fix-docgen-controls-enum-regression-2c03
Jun 23, 2026
Merged

JReinhold merged 4 commits into
nextfrom
jeppe-cursor/fix-docgen-controls-enum-regression-2c03

Conversation

@JReinhold

@JReinhold JReinhold commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #

What I did

Fixed a regression in the Controls table when experimentalDocgenServer is enabled. Stories that set an enum prop in args (for example the Example Button Large story with size: 'large') showed a text control instead of the radio control inferred from the component prop type.
When the docgen server flag is on, prepareStory now skips second-pass argTypes enhancers (inferArgTypes, inferControls) so customArgTypes stays annotation-only. mergeServiceArgTypes mirrors the legacy pipeline: server docgen as the extracted base, user annotations on top, then inference and control assignment.

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

  1. Open Storybook in the browser and navigate to the Primary button example: https://635781f3500dd2c49e189caf-yesmdjkodf.chromatic.com/?path=/story/example-button--primary
  2. Verify the size control is a radio with three options
  3. Navigate to the Large story: https://635781f3500dd2c49e189caf-yesmdjkodf.chromatic.com/?path=/story/example-button--large
  4. Verify the size control is still a radio button with three options. (before, it was a text control here)

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 pull request has been released as version 0.0.0-pr-35196-sha-b881a098. Try it out in a new sandbox by running npx storybook@0.0.0-pr-35196-sha-b881a098 sandbox or in an existing project with npx storybook@0.0.0-pr-35196-sha-b881a098 upgrade.

More information
Published version 0.0.0-pr-35196-sha-b881a098
Triggered by @ndelangen
Repository storybookjs/storybook
Branch jeppe-cursor/fix-docgen-controls-enum-regression-2c03
Commit b881a098
Datetime Tue Jun 23 12:04:13 UTC 2026 (1782216253)
Workflow run 28024804272

To request a new release of this pull request, mention the @storybookjs/core team.

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

Summary by CodeRabbit

Summary by CodeRabbit

  • Tests

    • Added/extended coverage for argument-type merging and argTypes inference, including enum controls and precedence rules.
    • Added assertions around experimental docgen server behavior for second-pass enhancer handling.
  • Bug Fixes

    • Improved argument type inference to avoid re-inference when user-authored argTypes already specify types.
    • When experimental docgen server is enabled, second-pass argTypes enhancers are skipped to prevent overriding expected structure.
  • Documentation

    • Clarified how custom argTypes and controls are layered during story preparation.

cursoragent and others added 3 commits June 16, 2026 22:07
When experimentalDocgenServer is on, prepareStory still runs inferArgTypes and
inferControls without client-side docgen. For stories that set an enum prop in
args (e.g. Large with size: 'large'), those inferred string/text argTypes were
layered on top of server docgen and overwrote the correct radio control.

Strip prepareStory-inferred type/control/options before merging custom argTypes
with the docgen payload, and skip inferArgTypes for args that already have a
type so live args cannot clobber extracted prop metadata.

Co-authored-by: Jeppe Reinhold <JReinhold@users.noreply.github.com>
Instead of stripping inferred fields at UI merge time, skip second-pass
argTypes enhancers in prepareStory when experimentalDocgenServer is enabled.
mergeServiceArgTypes now mirrors the legacy pipeline: server docgen as the
extracted base, user annotations on top, then inferArgTypes and inferControls.

Co-authored-by: Jeppe Reinhold <JReinhold@users.noreply.github.com>
Replace direct global.FEATURES assignment with vi.stubGlobal and
vi.unstubAllGlobals. Fix the @storybook/global mock to re-export the real
globalThis so stubGlobal is visible to prepareStory.

Co-authored-by: Jeppe Reinhold <JReinhold@users.noreply.github.com>
@JReinhold
JReinhold requested a review from AriPerkkio June 17, 2026 08:56
@JReinhold JReinhold self-assigned this Jun 17, 2026
@JReinhold JReinhold added bug ci:normal Run our default set of CI jobs (choose this for most PRs). docgen qa:skip Pull Requests that do not need any QA. (e.g. documentation) labels Jun 17, 2026
@coderabbitai

coderabbitai Bot commented Jun 17, 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: 1f16d0c4-a441-4f75-9df4-6881a27c4a6d

📥 Commits

Reviewing files that changed from the base of the PR and between 70109a4 and b881a09.

📒 Files selected for processing (1)
  • code/core/src/preview-api/modules/store/csf/prepareStory.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • code/core/src/preview-api/modules/store/csf/prepareStory.test.ts

📝 Walkthrough

Walkthrough

inferArgTypes now skips inference for args whose userArgTypes already declares a type. In prepareStory, argTypesEnhancers marked as secondPass are filtered out when global.FEATURES?.experimentalDocgenServer is enabled. Tests and documentation comments are updated to reflect both behaviors.

Changes

experimentalDocgenServer ArgTypes Inference Guards

Layer / File(s) Summary
inferArgTypes: skip pre-typed args
code/core/src/preview-api/modules/store/inferArgTypes.ts, code/core/src/preview-api/modules/store/inferArgTypes.test.ts
Object.fromEntries + filter replaces mapValues to exclude keys where userArgTypes[key]?.type is already set before passing to combineParameters. New test confirms enum type is preserved when size has a predefined type.
prepareStory: gate secondPass enhancers on experimentalDocgenServer
code/core/src/preview-api/modules/store/csf/prepareStory.ts, code/core/src/preview-api/modules/store/csf/prepareStory.test.ts
preparePartialAnnotations applies a filter step on argTypesEnhancers to drop secondPass enhancers when experimentalDocgenServer is set, then reduces the remainder. Tests update global mocking to use vi.stubGlobal/vi.unstubAllGlobals, adjust the vi.mock setup, update the existing FEATURES.argTypeTargetsV7 group, and add a new FEATURES.experimentalDocgenServer group asserting inference suppression and user control preservation.
mergeServiceArgTypes tests and comment updates
code/core/src/docs-tools/argTypes/docgenServiceArgTypes.test.ts, code/core/src/docs-tools/argTypes/docgenServiceArgTypes.ts, code/core/src/controls/components/ControlsPanel.tsx
New test file for mergeServiceArgTypes verifies four scenarios: enum type/control preservation, retention of user overrides, user control precedence, and enum behavior without the prop in story args. Comment updates in docgenServiceArgTypes.ts and ControlsPanel.tsx clarify the experimentalDocgenServer layering behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • storybookjs/storybook#35108: Adds renderer-converted argTypes to the docgen service payload and guards preview/manager registration behind experimentalDocgenServer, which works in tandem with this PR's second-pass enhancer skipping and pre-typed arg preservation.
✨ 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.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@code/core/src/preview-api/modules/store/csf/prepareStory.test.ts`:
- Around line 23-25: The vi.mock call for '`@storybook/global`' currently uses an
async factory function that simply re-exports the original module unchanged.
Replace this async factory function pattern with the simpler spy: true option in
the vi.mock call, which automatically spies on all exports while preserving
their original implementations. This follows the recommended coding guidelines
and simplifies the mock setup for the '`@storybook/global`' module.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fb62db52-5800-449f-a6bc-33a34f603248

📥 Commits

Reviewing files that changed from the base of the PR and between ff9d956 and 70109a4.

📒 Files selected for processing (7)
  • code/core/src/controls/components/ControlsPanel.tsx
  • code/core/src/docs-tools/argTypes/docgenServiceArgTypes.test.ts
  • code/core/src/docs-tools/argTypes/docgenServiceArgTypes.ts
  • code/core/src/preview-api/modules/store/csf/prepareStory.test.ts
  • code/core/src/preview-api/modules/store/csf/prepareStory.ts
  • code/core/src/preview-api/modules/store/inferArgTypes.test.ts
  • code/core/src/preview-api/modules/store/inferArgTypes.ts

Comment thread code/core/src/preview-api/modules/store/csf/prepareStory.test.ts Outdated
Add required name fields to argTypes in experimentalDocgenServer tests to
satisfy typescript-validation. Replace the passthrough async factory with
vi.mock(..., { spy: true }) per review feedback.

Co-authored-by: Jeppe Reinhold <JReinhold@users.noreply.github.com>
@JReinhold JReinhold mentioned this pull request Jun 21, 2026
51 of 61 tasks
Comment thread code/core/src/preview-api/modules/store/csf/prepareStory.ts
Comment thread code/core/src/preview-api/modules/store/csf/prepareStory.ts
@JReinhold
JReinhold merged commit 8e9f05a into next Jun 23, 2026
145 checks passed
@JReinhold
JReinhold deleted the jeppe-cursor/fix-docgen-controls-enum-regression-2c03 branch June 23, 2026 11:57
@ndelangen
ndelangen restored the jeppe-cursor/fix-docgen-controls-enum-regression-2c03 branch June 23, 2026 12:03
@github-actions github-actions Bot mentioned this pull request Jun 25, 2026
2 tasks done
This was referenced Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:normal Run our default set of CI jobs (choose this for most PRs). docgen qa:skip Pull Requests that do not need any QA. (e.g. documentation)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants