-
Notifications
You must be signed in to change notification settings - Fork 104
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
Warning: Can't perform a React state update on an unmounted component. #196
Comments
I agree, this appears to be a bug. I would guess that somehow the observer is not getting cancelled when it should. |
Interestingly I ran into this using react-osh, and then switched to react-easy-view only to find the issue here is well. It makes sense now as both libraries are using @nx-js/observer-util |
I am also running into this bug. Does someone have a solution for this? |
Is this a serious bug, or is it a "safe to ignore bug," like some that React reports? |
@mattmccray It may be serious. I would not recommend using this library until this is fixed. I haven't been able to find the culprit causing the issue yet, so our team decided to use different state management mechanisms. |
It appears to be in the https://codesandbox.io/s/errors-with-react-easy-state-forked-8yqc1?file=/src/App2.js |
I took a look at this problem and it is interesting because this is not an actual bug. At least not yet. This warning is caused because React, in
This is intentional. The React team does it to break components that contain side-effects. And in this case, they succeed. The specific problem of
I have forked @orballo's CodeSandbox and added console logs to make more obvious what is happening: https://codesandbox.io/s/errors-with-react-easy-state-forked-inj5z?file=/src/view.js. I have applied a fix to bypass the rerender on unmounted components. I say this is not an actual bug because rendering a component and never mounting it is something that React doesn't do right now, even in StrictMode. It does it in the development mode of StrictMode because React is trying to prepare libraries for the upcoming Concurrent mode. I have done a PR (#227) that checks if the component is mounted or not before triggering a rerender. It is the same fix I used in the CodeSandbox. But it is important to notice two things:
So, as a summary:
Finally, I'd like to mention that the memory leak forced by React in the development mode of StrictMode is minimal and shouldn't have any measurable impact while developing. |
In case you are curious, this is my proposal to add support for React Concurrent: #228 |
React Easy State version: 6.3.0
Platform: browser
Describe the bug
I get the following warning when editing an
<input/>
field while usingReact.StrictMode
:For tougher bugs
To Reproduce
In this CodeSandbox
Click
Switch to /about
, then click againSwitch to /
and enter some value in the<input />
element.You'll see the warning in console.
Expected behavior
I shouldn't see any warning.
I'm not sure if this is a bug or I'm doing something wrong. Either way I cannot figure out what's happening :/
The text was updated successfully, but these errors were encountered: