Proposal: non-blocking updates refactor #5534
Closed
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.
I do not intend for this PR to get merged, its just a proposal
Non-Blocking react-router
The main issue here is that in order to know the router state from a component this component must be either rendered using a
<Route component={Component}
or HoC'dwithRouter(Component)
and even then the component will probably not update itself when the route changes.This happens because
Route
doesnt update itself when the history changes. Because of react-router's context re-definition strategyRoute
components will basically hide thehistory
fromRoute
s that are deep into the VDOM tree behind a virtual history layer thats defined by its parent.I myself would much rather pay attention to the
Router
's history context because its global in a sense that I only care about what's in the user's browser address field, not what the current context allows me to see.This approach would make it much easier to listen to history changes from each of the
Route
s, each one would be able to tell if it should update itself or not depending on the way thepath
matches the currenthistory.location
.Here's a test case of what I'm trying to achieve (and the current implementation of react-router wont do)
Notice that the component only re-renders when the match is different