Make disposing unmounted routes more robust #50
Merged
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.
Closes #38
Closes #39
For #39, I found nothing of value in my investigation. Will continue investigating and re-open if needed.
In short, one feature of the router is that it will "dispose" any route that is not rendered anymore. This means the router will tell the Relay store that any queries used by the current route is no longer active, and can be GCed if appropriate. The feature itself is especially important for larger apps where the Relay store otherwise can become quite fat and memory intensive as you browse around.
Previously, this disposing was done via a regular
useEffect
that would trigger when a route render function was unmounted. However, a render function unmounting doesn't necessarily mean that the route has unmounted. For example, it could be temporarily unmounted because something suspended.This PR changes the mechanism that disposes unmounted routes from using a regular
useEffect
to actually pushing an event from the router when a route unmounts, and then checking by computedrouteKey
(which is unique per route + params) what's supposed to be disposed.