Repository navigation
Docgen: Fix inferred argTypes from initial args overriding docgen and custom argTypes in experimentalDocgenServer mode - #35196
Conversation
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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesexperimentalDocgenServer ArgTypes Inference Guards
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (7)
code/core/src/controls/components/ControlsPanel.tsxcode/core/src/docs-tools/argTypes/docgenServiceArgTypes.test.tscode/core/src/docs-tools/argTypes/docgenServiceArgTypes.tscode/core/src/preview-api/modules/store/csf/prepareStory.test.tscode/core/src/preview-api/modules/store/csf/prepareStory.tscode/core/src/preview-api/modules/store/inferArgTypes.test.tscode/core/src/preview-api/modules/store/inferArgTypes.ts
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>
Closes #
What I did
Fixed a regression in the Controls table when
experimentalDocgenServeris enabled. Stories that set an enum prop inargs(for example the Example Button Large story withsize: 'large') showed a text control instead of the radio control inferred from the component prop type.When the docgen server flag is on,
prepareStorynow skips second-pass argTypes enhancers (inferArgTypes,inferControls) socustomArgTypesstays annotation-only.mergeServiceArgTypesmirrors 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:
Manual testing
sizecontrol is a radio with three optionssizecontrol is still a radio button with three options. (before, it was atextcontrol here)Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsDeclare whether manual QA will be needed for this PR during the next release, through
qa:neededorqa:skipMake 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 runningnpx storybook@0.0.0-pr-35196-sha-b881a098 sandboxor in an existing project withnpx storybook@0.0.0-pr-35196-sha-b881a098 upgrade.More information
0.0.0-pr-35196-sha-b881a098jeppe-cursor/fix-docgen-controls-enum-regression-2c03b881a0981782216253)To request a new release of this pull request, mention the
@storybookjs/coreteam.core team members can create a new canary release here or locally with
gh workflow run --repo storybookjs/storybook publish.yml --field pr=35196Summary by CodeRabbit
Summary by CodeRabbit
Tests
Bug Fixes
argTypesalready specify types.argTypesenhancers are skipped to prevent overriding expected structure.Documentation
argTypesand controls are layered during story preparation.