Skip to content
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

Upgrading to React 17 on app level breaks UI #12408

Closed
Hypnosphi opened this issue Sep 8, 2020 · 41 comments
Closed

Upgrading to React 17 on app level breaks UI #12408

Hypnosphi opened this issue Sep 8, 2020 · 41 comments

Comments

@Hypnosphi
Copy link
Member

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

@shilman
Copy link
Member

shilman commented Sep 10, 2020

See: fa3a0f1#r42051265

@Hypnosphi
Copy link
Member Author

Hypnosphi commented Sep 10, 2020

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

@molebox
Copy link

molebox commented Sep 15, 2020

See: fa3a0f1#r42051265

hey @shilman I may have missed a release, has this been fixed already? Just wondering as im in the process of drawing up a proposal to introduce storybook into our workflow and the docs keep on failing due to this hook violation error.

@shilman
Copy link
Member

shilman commented Sep 15, 2020

@molebox not AFAIK. @Hypnosphi any ideas here?

@Hypnosphi
Copy link
Member Author

Remove react from DLL?

@shilman
Copy link
Member

shilman commented Sep 15, 2020

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

@molebox
Copy link

molebox commented Sep 17, 2020

I just updated to 6.1.0-alpha.10 and im am now seeing this on every canvas and the docs page doesnt work at all.

screencapture-localhost-9009-2020-09-17-13_42_13

@shilman
Copy link
Member

shilman commented Sep 25, 2020

@molebox Did you try removing node_modules and/or lockfiles and reinstalling? Also did you try running with --no-dll?

@Hypnosphi
Copy link
Member Author

Same with 16.14.0 + new JSX transform. --no-dll does help

@shilman shilman added this to the 6.1 core milestone Oct 15, 2020
@magic-akari
Copy link

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

@GrossDesignCo
Copy link

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

@shilman shilman changed the title Upgrading React to 17-pre on app level breaks manager UI Upgrading React to 17-pre on app level breaks UI Oct 23, 2020
@bcomnes
Copy link

bcomnes commented Oct 28, 2020

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.

nybbles added a commit to Bullfrog-Labs/bullfrog that referenced this issue Oct 28, 2020
See storybookjs/storybook#12408 (comment) for the temporary fix for React Storybook that kept pulling in React 16.
nybbles added a commit to Bullfrog-Labs/bullfrog that referenced this issue Oct 29, 2020
* Adding Firebase Emulator logs to .gitignore

* Integrating in LoginView and logging-in behavior

* Upgrading everywhere to React 17

See storybookjs/storybook#12408 (comment) for the temporary fix for React Storybook that kept pulling in React 16.

* Modifying FirebaseAuthComponent to work when there is no redirect URL.

* Changing App test to smoke test that works with routing
@shilman shilman changed the title Upgrading React to 17 on app level breaks UI Upgrading to React 17 on app level breaks UI Nov 2, 2020
@shilman shilman removed the tracked label Nov 4, 2020
@shilman
Copy link
Member

shilman commented Nov 4, 2020

Fixed in #12972 / 6.1-beta. Closing.

npx sb@next upgrade --prerelease

@shilman shilman closed this as completed Nov 4, 2020
@lailsonbm
Copy link

Thanks, @shilman!

@thany
Copy link

thany commented Nov 5, 2020

Having this problem as well. I can't upgrade to a nonstable version. Can you backport the fix into 6.0 please?

Also I'm on React 16 and --no-dll doesn't fix anything.

@shilman
Copy link
Member

shilman commented Nov 5, 2020

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

@NeOMakinG
Copy link

NeOMakinG commented Nov 20, 2020

Hello,

Is this supposed to work ? https://github.com/PrestaShop/prestashop-ui-kit/pull/108/files#diff-0c3746c19bb935bd629052ce8bafe30b5685b04ddf4c879ad49913c31ce59abcR1-R19

I've the same issue while trying to use a useEffect hook inside a mdx story (as I need to execute some JS after a component story is loaded, to make it work properly everytime you'r going to a story through the menu)

I was waiting for the version 6.1 to test if it works, but it looks like it doesn't :(

Maybe I'm not using it properly

@matthias-ccri
Copy link
Contributor

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 🙍‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests