react-router: Miss is broken
In alpha 6 the big refactor, the <Miss> component is broken. This happens because when the location subscriber resets the match count when it is called, the components do not re-register themselves, so the <Miss> component sees the matchCount as 0.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 14
- Comments: 23 (8 by maintainers)
If I understand correctly, in v4-alt and you can’t have multiple routes matching at once. But instead you can nest multiple routers?
I have not been able to try v4-alt yet but one thing I try to deduce from the code is if sub-routers must concern themselves with the full url or just the part relative to the parent router (like in v4 with match). That compose-ability that v4 allows by only concerning children with only the part that is relative is quite amazing and it would be sad if that isn’t kept. If it is kept I don’t have much to say for v4 vs v4-alt. Both have things going for them and the react-approach is really the nicest router API I have ever seen so I think either one is great.
Seeing the same thing here & when using the MatchWhenAuthorized component pattern as well (so maybe something racey caused by that using subcomponents).
I actually may be seeing a similar bit of weirdness with
componentWillMountandcomponentWillUnmounton the subcomponents of what are two mutually exclusive routes.When a first, currently active route (but listed second in the markup) goes invalid and unmatches at the same time that the second one (but listed first) matches, the
componentWillUnmounteffects in the subcomponents from the original matched route end up firing AFTER thecomponentWillMounteffects of the subcomponents in the newly matched one. And if both of those overlapping mismatched methods modify, say, the same place of a redux store, then the state will end up as the now unmounted component intended rather than as the newly mounted component would have it.Reverse the markup order of the two Matches (and start on the other one from before and navigate back), and the oddity reverses as well.
Now obviously one problem here is causing side-effects in
componentWillMountwhen per React docs those should go incomponentDidMount(though that leads to double rendering). But it’s an unintuitive a gotcha that could be at work here in Match/Miss, maybe? Here’s a pen of the effect, http://codepen.io/dtipson/pen/dOKYvr?editors=1111 (open the console, note how the switch from B to A works).Also note that this is a factor when you list HOCs parallel to each other and each decides whether to render their subcomponents or not. If they’re mutually exclusive (that is, some prop decides which to display in a ternary or logical stack), the weirdness vanishes.
This issue is about the published alpha version. The current state of the v4 branch is much different. It doesn’t even have Miss anymore, etc.
I think the published version is too broken to use, at the moment.
On Mon, Dec 19, 2016 at 7:45 AM Rasmus Eneman notifications@github.com wrote: