-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
match object is always newly created #5099
Comments
Yes, this is intentional. You should implement your own sCU to use the semantics you prefer, checking on the field values that matter to your component's updating. Simple equality could be misleading, because the match object's properties could change if we re-used the object. Also, it would be messy to track the existing object because computeMatch would need to keep it around and there can be multiple matches within the same tree. |
It's impossible to safely implement an sCU to take care of this because child routes may use arbitrary params. If a higher level route component only cares about
In that case you'd make a new Object - you just memoize @timdorr I am happy to submit a PR if you believe this should be handled in the RR4 API. |
This was a huge gotcha, it's causing an unnecessary rerender on a handful of components.
@timdorr could you give some info on this? I assume i think @greenimpala has a good idea in the memoization. @timdorr could you confirm if that'd be an acceptable PR? |
Any news on this? It's causing us unnecessary re-renders on our PureComponent main view invalidating all our immutability efforts. @timdorr Is there at least a way to prevent the Route from injecting the match object into the component's props? |
I'd also love additional info on this @timdorr There has to be another alternative than writing massive amounts of sCUs. That just isn't practical for large scale projects |
Any update on this issue, i just started optimising my app and i found this to be a big problem for me. |
Same here, just ran into this issue when I was optimizing a project. Any updates? Thanks in advance. |
well what i have done is don't pass whole match object , just extract whatever prop you need in child component and pass that. |
@shahzad31 thanks for the quick reply, can you give more information? At what moment in the component's life cycle are you extracting the props? |
<Route>
components passprops.match
as a fresh object when the URL / params have not changed. Is this by design? This was not the case with RR V3. This breaks the PureComponent paradigm. See codepen below for example.Version
4.0.0
Test Case
https://codepen.io/anon/pen/NjYwZO?editors=1112
Steps to reproduce
Render a PureComponent within a
Route
.Expected Behavior
If the URL has not changed then re-renders of the
Route
should be passed the same props.Actual Behavior
match
is always a new object causing the component to be re-rendered. Even though its contents are unchanged.The text was updated successfully, but these errors were encountered: