When a React RouteNode should re-render?
See original GitHub issueHello @troch! I’m having a big doubt after a bug emerged in my react-mobx plugin.
My version of RouteNode
is based on yours react-router5 version .
Now I’ve noticed that in your version whenever a route change happens all your RouteNodes will re-render.
This usually works when your component structure resemble exactly a single tree and of course the visual changes will only happen in the children branches of the intersection RouteNode (because of the switch
or any other means to select the sub-components).
Nonetheless all RouteNodes are being re-rendered.
I think that this might be inefficient and I put in place a logic to re-render only the intersection node. In this case when the component structure is a tree it works because all the subcomponent of the intersection are re-generated and so any RouteNode in this branch will be re-generated and will select the correct subcomponents even tough it’s not the intersection (this is a render, not a re-render).
Now this logic turned to be buggy for some specific cases (example: app.a({id:1}).b -> app.a({id:2}).c
) so I tough to add an extra condition:
Re-render a RouteNode only when:
- it represents the intersection node
- or the segment associated with RouteNode is one of the segments toActivate
I tough preventing re-rendering RouteNodes might be necessary when you have a lot of them and only few of them really need to. Or when your component structure is organized in multiple parallel trees for example.
What do you think? But most important, am I overcomplicating this and I should just trust React and its internal algorithms? 😆
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (8 by maintainers)
I think I can refine it. It will reload if:
I guess that makes sense since when nesting
routeNode
HoCs, children route nodes of an updating route node don’t get local state updates. I think I need to introduce a key inrouteNode
or other fix.