-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Addon Docs: Remove react
peer dependency
#24881
Conversation
Well done Jeppe! |
New, updated, and removed dependencies detected. Learn more about Socket for GitHub ↗︎
🚮 Removed packages: html-webpack-plugin@5.5.3 |
👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎ This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. Ignoring: Next stepsTake a deeper look at the dependencyTake a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev. Remove the packageIf you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency. Mark a package as acceptable riskTo ignore an alert, reply with a comment starting with |
react
peer dependency from addon-docs
react
peer dependency
@SocketSecurity ignore @vitejs/plugin-vue@4.4.0 |
Looks like this work is conflicting with the recent work to support RSC, @shilman |
…ct' of github.com:storybookjs/storybook into addon-docs-without-react
…rybook into addon-docs-without-react
Tested this manually across all the project permutations, and everything works as expected. The cases that don't work are already known. 🎉 |
react
peer dependencyreact
peer dependency
@JReinhold merge? |
Works on #25179
This PR is an investigation into the possibility of removing React as a peer dependency of
addon-docs
, originally proposed at #24823.Objective
Remove
react
andreact-dom
as a peer dependency ofaddon-docs
- or alternatively turn into an optional peer dependency.We want to enable non-React users to use
addon-docs
without needing to install React themselves and “bloating” their packages. React will no doubt remain innode_modules
as a transitive dependency, but that still feels nicer.Questions we want to answer
addon-docs
, while still allowing React users to use their own instance of React?👆is important, because React users need to be able to define which version of React they want to use for rendering their components and stories.
Findings
We’ve found a strategy to supply
react
andreact-dom
by default withaddon-docs
(via a direct dependency) while still allowing users to supply their own instance and version by simply installing the packages in the root project if they want to. We’ve proved that this strategy works in almost1 all situations.This way, if the user does not have
react
installed,react@18.2.0
fromaddon-docs
will be used.The strategy is to attempt to get the path to
react
usingrequire.resolve('react')
.@storybook/core-server
and@storybook/react
presets, which will either get the user’s rootreact
dependency, or fail. It will never resolve to thereact
in@storybook/addon-docs
resolvedReact
property on presets.addon-docs
we get thatresolvedReact
preset and if it’s empty (because the user didn’t havereact
in the root) we do the same resolution which will always resolve to thereact
thataddon-docs
has.addon-docs
webpackFinal
andviteFinal
we alias all imports ofreact
,react-dom
and@mdx-js/react
2 to the paths defined inresolvedReact
.react
are either from the root or fromaddon-docs
.Remaining Work
This PR is just a spike that proves this can work, there's more work to be done for this to be releasable.
See #25179
Find out why the unit test is failing, maybe the React import needs aliased as wellUpdate documentation to not say React is necessary - if we do thatUpdate documentation to note that users can specify their own React version for docs if they need toAutomigration to remove React as a dependency if possible - there might be a lot of edge cases here making this "if possible" detection very hardStop adding React dependencies oninit
Test in all permutations of builders package managers and operating systemsWe might want to make it possible to opt-out of this, because there could be unknown unknowns where this strategy brakes users' setupsE2E Test
I propose that we add an E2E test that verifies that React is available in MDX.
version
fromreact
and displays itManual Test
Before merging this we should manually test it in multiple project permutations:
node_modules
node_modules
node_modules
node_modules
node_modules
node_modules
This pull request has been released as version
0.0.0-pr-24881-sha-6ea23655
. Install it by pinning all your Storybook dependencies to that version.More information
0.0.0-pr-24[8](https://github.com/storybookjs/storybook/actions/runs/7207572473/job/19634682139#step:10:8)81-sha-6ea23655
addon-docs-without-react
6ea23655
1702549604
)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 canary-release-pr.yml --field pr=[24](https://github.com/storybookjs/storybook/actions/runs/7207572473/job/19634682139#step:10:24)881
Footnotes
This doesn’t work in the specific combination of Yarn PnP + Non-React framework + user having its own React version in the root package. It doesn’t break, but it will always use
react@18.2.0
fromaddon-docs
and ignore thereact
in the root. We think this is okay because:Bullet 2 and 3 seems highly unlikely to appear at the same time, why would a Svelte user care about which React version their docs are using?
It has a workaround, the user can set the
resolvedReact
property inmain.ts
manually withrequire.resolve('react')
↩Webpack has a weird behavior with
@mdx-js/react
and symlinked stories like our template-stories in the monorepo. If the user has a custom React version installed,@mdx-js/react
will not be hoisted fromaddon-docs
, and then Webpack can't find it when rendering symlinked MDX files. So we explicitly alias it to fix this - this doesn't seem to be necessary in Vite projects. ↩