Skip to content

React: Add optional React type peers to packages that publish React-based declarations#34641

Merged
JReinhold merged 5 commits into
nextfrom
copilot/fix-peer-dependencies-react-types
Apr 28, 2026
Merged

React: Add optional React type peers to packages that publish React-based declarations#34641
JReinhold merged 5 commits into
nextfrom
copilot/fix-peer-dependencies-react-types

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 27, 2026

Closes #34640

What I did

Several published Storybook packages ship .d.ts files that import from react and/or react-dom, but did not declare the corresponding @types/* packages as accessible dependencies. This breaks stricter package resolvers such as pnpm's global virtual store, where those transitive type packages are no longer implicitly available.

Details
  • Add optional React type peers

    • Added @types/react as an optional peer dependency for packages whose published declarations reference React types:
      • @storybook/addon-docs
      • @storybook/addon-links
      • storybook
      • @storybook/nextjs
      • @storybook/nextjs-vite
      • @storybook/react
      • @storybook/react-dom-shim
  • Add optional React DOM type peers where needed

    • Added @types/react-dom as an optional peer dependency for packages whose published surface also depends on React DOM typings:
      • @storybook/react
      • @storybook/react-dom-shim
      • @storybook/nextjs
      • @storybook/nextjs-vite
  • Keep non-React consumers unaffected

    • Marked the new peers as optional via peerDependenciesMeta, so projects that do not use these React-typed surfaces are not forced to install them.

Example of the manifest change pattern:

{
  "peerDependencies": {
    "@types/react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
    "@types/react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
  },
  "peerDependenciesMeta": {
    "@types/react": { "optional": true },
    "@types/react-dom": { "optional": true }
  }
}

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!

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

  • 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>

Summary by CodeRabbit

  • Chores
    • React TypeScript type definitions (@types/react and @types/react-dom) are now declared as optional peer dependencies across packages, allowing consumers to omit installation without errors while maintaining type compatibility when present.

Copilot AI and others added 3 commits April 27, 2026 09:44
Agent-Logs-Url: https://github.com/storybookjs/storybook/sessions/0404ed78-06b5-4a1d-9efa-d49a6bf76017

Co-authored-by: JReinhold <5678122+JReinhold@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missing peer dependencies for React types Add optional React type peers to packages that publish React-based declarations Apr 27, 2026
Copilot AI requested a review from JReinhold April 27, 2026 09:58
@JReinhold JReinhold added bug react patch:yes Bugfix & documentation PR that need to be picked to main branch typescript ci:normal labels Apr 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 27, 2026

Fails
🚫 The "#### Manual testing" section must be filled in. Please describe how to test the changes you've made, step by step, so that reviewers can confirm your PR works as intended.

Generated by 🚫 dangerJS against 54ec170

@JReinhold JReinhold changed the title Add optional React type peers to packages that publish React-based declarations React: Add optional React type peers to packages that publish React-based declarations Apr 27, 2026
@JReinhold JReinhold requested a review from ndelangen April 27, 2026 10:06
@JReinhold JReinhold marked this pull request as ready for review April 27, 2026 10:06
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

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: 02ece88d-ca33-4b95-bbe2-4896b20c8b75

📥 Commits

Reviewing files that changed from the base of the PR and between 77ff820 and 54ec170.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (7)
  • code/addons/docs/package.json
  • code/addons/links/package.json
  • code/core/package.json
  • code/frameworks/nextjs-vite/package.json
  • code/frameworks/nextjs/package.json
  • code/lib/react-dom-shim/package.json
  • code/renderers/react/package.json

📝 Walkthrough

Walkthrough

Seven packages across the monorepo add @types/react and optionally @types/react-dom as optional peer dependencies, using matching React version ranges and marking them as optional in peerDependenciesMeta.

Changes

Cohort / File(s) Summary
Packages with @types/react only
code/addons/docs/package.json, code/addons/links/package.json, code/core/package.json
Add @types/react as optional peer dependency with React version range ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 in both peerDependencies and peerDependenciesMeta.
Packages with @types/react and @types/react-dom
code/frameworks/nextjs/package.json, code/frameworks/nextjs-vite/package.json, code/lib/react-dom-shim/package.json, code/renderers/react/package.json
Add @types/react and @types/react-dom as optional peer dependencies with matching React version ranges in both peerDependencies and peerDependenciesMeta.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes


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

@storybook-app-bot
Copy link
Copy Markdown

Package Benchmarks

Commit: 54ec170, ran on 27 April 2026 at 10:18:30 UTC

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

@storybook/react-dom-shim

Before After Difference
Dependency count 0 0 0
Self size 19 KB 19 KB 🚨 +266 B 🚨
Dependency size 791 B 1 KB 🚨 +312 B 🚨
Bundle Size Analyzer Link Link

@JReinhold JReinhold merged commit d0d6e23 into next Apr 28, 2026
122 of 123 checks passed
@JReinhold JReinhold deleted the copilot/fix-peer-dependencies-react-types branch April 28, 2026 14:42
@JReinhold JReinhold removed the patch:yes Bugfix & documentation PR that need to be picked to main branch label May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Many packages' types relies on @types/react without explicitly depending on it

3 participants