Add support for React 18
See original GitHub issueIs your feature request related to a problem? Please describe
Only so far as upgrading to React 18 is concerned 😃
Specifically, when I try to update my devDependencies
, @storybook/addon-controls
throws an error, because it’s peerDependencies
is set to only React 16 and 17.
Doublechecked in the package.json https://github.com/storybookjs/storybook/blob/next/addons/controls/package.json#L61-L64
There’s probably already some awareness of this and/or a fix in flight, but just in case I thought I’d mention it.
Describe the solution you’d like
Ideally I think it’s as simple as updating the peerDependencies
throughout Storybook’s packages, but I’m sure there’s some additional work in the ReactDOM.render > ReactDOM.createRoot transition that would affect Storybook’s rendering cycle.
Describe alternatives you’ve considered
None as yet
Are you able to assist to bring the feature to reality?
I’m happy to make a PR to update the peerDeps, if it was deeper than that I’d be lost 😃
Issue Analytics
- State:
- Created a year ago
- Reactions:68
- Comments:79 (27 by maintainers)
Olé!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.5.0-alpha.54 containing PR #17853 that references this issue. Upgrade today to the
@next
NPM tag to try it out!This is a temporary fix. Full fix still coming in https://github.com/storybookjs/storybook/pull/17215
@alberto-f Thank you for your concerns.
I try to do my best to summarize everything important to the React 18 support.
Next steps
As discussed with the maintainers, we didn’t want to use the new Root API to mount Storybook to the DOM because this would require profound testing of Storybook and all of its plugins. I am sure this will be done in one of the next iterations. Maybe @shilman could give some feedback in this regard.
Questions
Which React version your components use relies on your installed React version. If you are installing React in version 18, then version 18 is used. The difference is only whether the concurrent features are activated. And this depends of whether the components are mounted with the new Root API or the legacy one. As already mentioned, if React 18 is in use and you haven’t opt-out from the new Root API, the Root API is used, and all concurrent features are “activated”.
Storybook supports mounting your components in React 18 with the new Root API. If still, some errors occur, please open a new ticket with a reproducible example. Often, the issue was related to an existing yarn.lock file, which didn’t allow to resolve dependencies correctly. In some other cases, some transitive dependencies were not ready for React 18. Ideally, the support should be fine (except for the console error message from React, which tells you, that the Storybook Manager still uses the old API)
Hacks shouldn’t be needed at all. I know that npm users might have the
legacy-peer-deps
issue because some transitive dependencies haven’t defined React 18 as a valid React version. That’s indeed awkward. Please create a new ticket if you still have any issues (except for the console error from React). I am sure it will be taken care of as soon as possible.