Skip to content

React: Preserve discriminated union prop values in metadata extraction - #35844

Merged
ndelangen merged 4 commits into
storybookjs:nextfrom
s-robertson:u/srobertson/fix-react-component-meta-union-props
Aug 18, 2026
Merged

ndelangen merged 4 commits into
storybookjs:nextfrom
s-robertson:u/srobertson/fix-react-component-meta-union-props

Conversation

@s-robertson

@s-robertson s-robertson commented Aug 11, 2026 •

Copy link
Copy Markdown

What I did

Fix react-component-meta prop extraction for discriminated unions where the same prop has different types across union members.

Previously, the extractor retained the first prop symbol while deduplicating union members, causing later literal values to be omitted. It now uses TypeScript's merged property type for serialization while preserving the original symbol for documentation, defaults, declarations, and source filtering.

Added a regression test confirming an optional discriminant with "a" and "b" variants includes both values.

AI assistance: OpenAI Codex was used to investigate, implement, and test this change. I reviewed and submitted the result.

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

No browser-based manual testing is necessary. This change only affects TypeScript component metadata extraction and is covered by the regression test.

A maintainer can verify it by running:

  1. cd code/renderers/react
  2. node ../../../node_modules/vitest/vitest.mjs run --config vitest.config.ts src/componentManifest/componentMeta/componentMetaExtractor.props.test.ts
  3. Confirm all tests pass, including merges same-named prop types across union members.

Documentation

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

Documentation updates are not applicable because this fixes existing experimental extraction behavior without changing its API or configuration.

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>

@github-actions

github-actions Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
Fails
🚫

PR is not labeled with one of: ["qa:needed","qa:skip","qa:success"]

Generated by 🚫 dangerJS against 3337ce4

@s-robertson s-robertson changed the title fix(react): merge discriminated union prop types React: Preserve discriminated union prop values in metadata extraction Aug 11, 2026
@s-robertson
s-robertson marked this pull request as ready for review August 11, 2026 18:40
@coderabbitai

coderabbitai Bot commented Aug 11, 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 Plus

Run ID: 8821720a-80d9-4b52-a782-a6739b7ad6a3

📥 Commits

Reviewing files that changed from the base of the PR and between 9164b22 and 7079faf.

📒 Files selected for processing (2)
  • code/renderers/react/src/componentManifest/componentMeta/componentMetaExtractor.props.test.ts
  • code/renderers/react/src/componentManifest/componentMeta/componentMetaExtractor.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • code/renderers/react/src/componentManifest/componentMeta/componentMetaExtractor.props.test.ts
  • code/renderers/react/src/componentManifest/componentMeta/componentMetaExtractor.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review.


Walkthrough

Changes

Union Prop Serialization

Layer / File(s) Summary
Prop type override
code/renderers/react/src/componentManifest/componentMeta/componentMetaExtractor.ts
extractPropItem can serialize an explicitly resolved property type.
Union property resolution and coverage
code/renderers/react/src/componentManifest/componentMeta/componentMetaExtractor.ts, code/renderers/react/src/componentManifest/componentMeta/componentMetaExtractor.props.test.ts
Union properties use types resolved from the complete union. Tests cover optionality, inherited properties, never exclusions, and combined enum values.

Possibly related PRs

Merge Risk: ⚪ Minimal · up to 7079f

This localized fix preserves all literal values for discriminated-union props during metadata extraction and includes a regression test; no actionable merge-blocking risk remains beyond normal checks and review.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@ndelangen ndelangen added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Aug 18, 2026
@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@ndelangen ndelangen added the ci:normal Run our default set of CI jobs (choose this for most PRs). label Aug 18, 2026
@ndelangen
ndelangen merged commit 50f703d into storybookjs:next Aug 18, 2026
134 of 135 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Core Team Projects Aug 18, 2026
huang-julien added a commit to storybookjs/sandboxes that referenced this pull request Aug 18, 2026
Check the diff here: storybookjs/storybook@f96ed20...add38a0

List of included PRs since previous version:
- storybookjs/storybook#35922 (valentin/sb-1766-angular-docgen-documentation-pass)
- storybookjs/storybook#35844 (s-robertson/u/srobertson/fix-react-component-meta-union-props)
- storybookjs/storybook#35931 (valentin/sb-1847-componentid-collision-warning)
- storybookjs/storybook#35923 (valentin/sb-1789-server-side-code-snippets-resolve-spreads-and-identifier)
- storybookjs/storybook#35940 (valentin/sb-1789-review-fixes)
- storybookjs/storybook#35900 (julien/vue-api-description)
- storybookjs/storybook#35938 (fix-publish-ansi-parsing)
- storybookjs/storybook#35929 (valentin/sb-1821-pin-oxc-resolver)
- storybookjs/storybook#35936 (chore/changelog-v10.5.9)
- storybookjs/storybook#35930 (valentin/sb-1789-review-fixes)
- storybookjs/storybook#35921 (valentin/sb-1809-bug-angular-constructor-and-generic-function-inputs-lose-the)
- storybookjs/storybook#35917 (norbert/fix-publish-staged-retries)
- storybookjs/storybook#35896 (valentin/sb-1776-angular-docs-end-to-end)
- storybookjs/storybook#35920 (julien/vue_server_docgen_options)
- storybookjs/storybook#35907 (valentin/docgen-server-arg-types)
- storybookjs/storybook#35886 (valentin/sb-1799-default-docgen-server-angular-vite)
- storybookjs/storybook#35902 (fix/vue-snippet-runtimeoverride)
- storybookjs/storybook#35825 (norbert/module-graph-skip-noop-mirror)
- storybookjs/storybook#35629 (reuben/fix-pseudo-states-cssom-rewrites)
- storybookjs/storybook#35915 (next-merge-prerelease)
- storybookjs/storybook#35906 (valentin/angular-docs-decorator-gate)
- storybookjs/storybook#35830 (version-non-patch-from-10.6.0-alpha.5)
- storybookjs/storybook#35899 (valentin/angular-required-input-with-default)
- storybookjs/storybook#35831 (norbert/spike-module-graph-hot-cold-split)
@github-actions github-actions Bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Aug 20, 2026
hasanshahriar32 pushed a commit to Paradox-Tech-BD/nirog-storybook that referenced this pull request Aug 22, 2026
…x-react-component-meta-union-props

React: Preserve discriminated union prop values in metadata extraction
(cherry picked from commit 50f703d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-scan:human bug ci:normal Run our default set of CI jobs (choose this for most PRs). docgen patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch react sev:S3 Medium priority. Fix within months if possible. typescript

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants