-
Notifications
You must be signed in to change notification settings - Fork 154
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
Guard setState with isMounted #40
Conversation
Firing two actions close together, where one action changes state for a watched store, and the other action results in the removal of the watching component from the DOM, can produce "Error: Invariant Violation: replaceState(...): Can only update a mounted or mounting component." from React. The setState call therefore needs to be guarded even though componentWillUnmount removes the listener.
Thanks, @randallsquared. If you have a simple example that can consistently reproduce this error, I'll incorporate it into the test suite; otherwise I'll write a more naïve test case. |
Disentangling from my app will take some time, so I don't have one offhand. I can have a test in later this week, if you wanted to wait for it. |
That sounds fine to me. Thanks very much! |
I have the same problem. |
…swapped out from under the root; also lots of miscellaneous surgery to avoid jsdom's Wrong Document.
So, I ended up doing quite a lot of surgery to that test, and I'm sure that it's not as clean as it might be. The two main causes of the extraneous changes were avoiding React's triggering of jsdom's "Wrong Document" error [1] and using FluxChildMixin and FluxMixin. Probably this could be refactored to remove those last two, since the reason I reintroduced them was to try to avoid Wrong Documents, but it turned out that clearing the require cache was what was really needed. [1] https://groups.google.com/forum/#!topic/reactjs/5UlF-mBsG2o |
Okay, I did a bit of digging into this issue. Here's what's happening to cause the bug:
Based on nodejs/node-v0.x-archive#7872, this is the intended behavior in I'm going to merge this as is, and work on cleaning up the tests some other time. Thanks so much @randallsquared for the code! |
Firing two actions close together, where one action changes state for a watched store, and the other action results in the removal of the watching component from the DOM, can produce "Error: Invariant Violation: replaceState(...): Can only update a mounted or mounting component." from React. The setState call therefore needs to be guarded even though componentWillUnmount removes the listener.
I haven't written a test for this, yet.