Fix React's StrictMode warning: unmounted component rerender #227
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
This PR fixes the warning that appears in development when using React's StrictMode, explained in more detail in #196.
It doesn't fix the memory leak that will happen in React Concurrent mode. To talk about that I will open a new issue.
Proposed changes
I have added a flag to check if a component was finally mounted or not. If the component was not mounted, we avoid calling its
setState
.I have also added another flag for the case when a reaction was invalidated before the component was mounted. If I am not mistaken, this cannot happen in React right now, but it can happen in React Concurrent mode, so why not add it now.