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

React "Rendered fewer hooks than expected" or other error when refreshing component inside HOC/renderprop #266

Closed
Bnaya opened this issue Dec 9, 2020 · 3 comments · Fixed by #353

Comments

@Bnaya
Copy link

Bnaya commented Dec 9, 2020

When updating HOC-wrapped component to a different number//kinds of hooks, you get the "Rendered fewer hooks than expected" error from React

Repro:
https://codesandbox.io/s/react-refresh-webpack-plugin-rendered-more-hooks-than-during-the-previous-render-issue-ezcrz?file=/src/Comp.js

Delete or add one of the hooks there, and you should get the error

Background:
at mobx we've got a bug report, and we've figured it's not on mobx side, but react-refresh/the webpack plugin
mobxjs/mobx#2668, as in the above repro.

After some debugging, It seems like when HOC, renderprops or similar composition patterns are involved,
The the relevant components aren't getting signature hash,
And React, when the old and new component does not have a signature, tries to refresh the component anyhow:
https://github.com/facebook/react/blob/9aca239f11f31109dc1a229aa1571c2bf02f5524/packages/react-refresh/src/ReactFreshRuntime.js#L126-L132

I've opened the issue here because injecting the hash for a component in a co-op between the plugin and react-refresh.
I've going to open the issue there as-well

Keywords:
Rendered more hooks than during the previous render
Rendered fewer hooks than expected

@gaearon
Copy link

gaearon commented Mar 26, 2021

facebook/react#21104

@gaearon
Copy link

gaearon commented Mar 30, 2021

[email protected] is out with the fix.

@jens-duttke
Copy link

Is this plugin still maintained? Is there a plugin that is updated more regular?
Or what would be the recommended way to use react-refresh with Webpack?

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

Successfully merging a pull request may close this issue.

3 participants