storybook: Upgrading to React 17 on app level breaks UI

Here’s the repro: https://github.com/Hypnosphi/test-storybook-react-17

Error I get is:

react.development.js:1431 Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
    at resolveDispatcher (react.development.js:1431)
    at Object.useContext (react.development.js:1439)
    at useTheme (emotion-theming.browser.esm.js:112)
    at useMenu (vendors~main.619dfba2fee0a3e45bd3.bundle.js:25841)
    at Object.mapper [as current] (vendors~main.619dfba2fee0a3e45bd3.bundle.js:26274)
    at ManagerConsumer (vendors~main.619dfba2fee0a3e45bd3.bundle.js:1484)
    at renderWithHooks (vendors~main.619dfba2fee0a3e45bd3.bundle.js:42664)
    at mountIndeterminateComponent (vendors~main.619dfba2fee0a3e45bd3.bundle.js:45343)
    at beginWork (vendors~main.619dfba2fee0a3e45bd3.bundle.js:46457)
    at HTMLUnknownElement.callCallback (vendors~main.619dfba2fee0a3e45bd3.bundle.js:28049)

Brief debugging showed that useTheme imports React from DLL while the rest of manager UI imports it from node_modules/@storybook/ui/node_modules/react

Screenshot 2020-09-08 at 04 15 20 Screenshot 2020-09-08 at 04 16 04

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 14
  • Comments: 41 (24 by maintainers)

Commits related to this issue

Most upvoted comments

Fixed in #12972 / 6.1-beta. Closing.

npx sb@next upgrade --prerelease

Thanks @dburles we’re trying to get it back into latest now 😅

Any plans to also increase the react-dom range to support 17?

Edit, looks like there are issues with npm 7 + storybook as well.

--no-dll works with React 17 as well.

“yarn storybook --no-dll” works for me

NOTE: this is hopefully fixed in 6.1 ☝️ . We need to get it back into the stable release, but are having problems with repros in CI. In the meantime if people can upgrade to 6.1 to test it out, please give it a try and report back:

npx sb upgrade --prerelease

If it doesn’t work right away, try removing regenerating lockfiles.

I was able to get this working on react 17 by turning off the new JSX transform.

In the tsconfig

-   "jsx": "react-jsx",
+   "jsx": "react",

And add import * as React from 'react'; in all JSX files as needed. After that, you can wipe the tears off your keyboard 🙍‍♂️

Thanks @dburles we’re trying to get it back into latest now 😅

Ta-da!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.0.27 containing PR #12874 that references this issue. Upgrade today to the @latest NPM tag to try it out!

npx sb upgrade

@thany unfortunately we can’t backport it easily. instead we’re expediting the 6.1 stable release, due in a week or so.

+1, --no-dll worked for me with React 17 as well

Jeepers creepers!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.1.0-alpha.30 containing PR #12908 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb upgrade --prerelease

Closing this issue. Please re-open if you think there’s still more to do.

Thanks @shayc ! Will check it out later today

@shilman it turned out not to be the actual reason, but is worth fixing anyway

@shilman The reproduction with React experimental I posted works on 6.1.0-alpha.31

@dburles thanks for the repro. seeing same as above ☝️ – works with yarn fails with npm. not sure what to do other than the workaround. suggestions welcome!

w00t!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.1.0-alpha.28 containing PR #12874 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb upgrade --prerelease

Closing this issue. Please re-open if you think there’s still more to do.

I’m hoping we can get rid of the DLLs entirely in 6.1. Fingers crossed 🤞

@molebox not AFAIK. @Hypnosphi any ideas here?