question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for React 18

See original GitHub issue

Is 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:closed
  • Created a year ago
  • Reactions:68
  • Comments:79 (27 by maintainers)

github_iconTop GitHub Comments

23reactions
shilmancommented, Apr 1, 2022

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!

npx sb upgrade --prerelease

This is a temporary fix. Full fix still coming in https://github.com/storybookjs/storybook/pull/17215

22reactions
valentinpalkoviccommented, Aug 4, 2022

@alberto-f Thank you for your concerns.

I try to do my best to summarize everything important to the React 18 support.

  1. Storybook will render your components with the new root API as soon as React 18 is installed. You can opt-out from this if you want. Then the legacy root API is used to mount your components
  2. Storybook itself, the Storybook manager, is written in React, too. And it relies on the React version, which is installed in your project. It doesn’t provide its very own React version. Therefore, if React 18 is used in your project, the Storybook Manager uses it as well, but will still use the legacy root API to mount itself to the DOM. This mounting has nothing to do with how your components are mounted to the DOM.

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

If I see the error once, Are my components using react v18 or react v17 ?

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”.

Is there any ticket to get information about when Storybook will fully support react v18 as this one has been closed?

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)

This thread provides hacks to move forward and use react 18, but it is soooo lengthy that it is difficult to follow.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Upgrade to React 18
When you first install React 18, you will see a warning in the console: ReactDOM.render is no longer supported in React 18.
Read more >
React 18 Upgrade Guide and New Features - Refine Dev
React 18 was released! Are you looking to upgrade to React 18? Learn about the new features and changes in this comprehensive guide....
Read more >
Upgrading to React 18 with TypeScript - LogRocket Blog
After a significant period of time in alpha and beta, React 18 shipped on March 29th 2022. Since the first alpha was released,...
Read more >
Upgrade to react 18 — Issues and resolution - Dev Genius
In version 8, React Redux's two public APIs ( connect and useSelector ) are rewritten to support React 18. npm install react-redux. 5....
Read more >
React 18 Migration | Nx
If you use npm v7/v8, you will need to use npm install --force after running nx migrate 14.0.0 since @testing-library/react-hook does not support...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found