-
Notifications
You must be signed in to change notification settings - Fork 49k
Closed
Description
React version: 17.0.0
Steps To Reproduce
- https://codesandbox.io/s/react-refresh-webpack-plugin-rendered-more-hooks-than-during-the-previous-render-issue-ezcrz?file=/src/Comp.js
- Delete one of the hooks there
Link to code example:
https://codesandbox.io/s/react-refresh-webpack-plugin-rendered-more-hooks-than-during-the-previous-render-issue-ezcrz?file=/src/Comp.js
The current behavior
You get "Rendered more hooks than during the previous render" error
The expected behavior
Should hot reload and re-mount the component.
The source of the issue have two parts:
- react-refresh and the bundler fails to inject signature to the component
- When no signature apparent,
react-refresh
consider the components as compatible, which is not always true, as in the reproreact/packages/react-refresh/src/ReactFreshRuntime.js
Lines 126 to 132 in 9aca239
function haveEqualSignatures(prevType, nextType) { const prevSignature = allSignaturesByType.get(prevType); const nextSignature = allSignaturesByType.get(nextType); if (prevSignature === undefined && nextSignature === undefined) { return true; }
I've filed an issue also for the webpack plugin: pmmmwh/react-refresh-webpack-plugin#266
Mobx related issue: mobxjs/mobx#2668
rvion, JustHollow, joaovct, yuhongda and ganor38