-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Investigate when a context from another library causes us to opt out of perf optimizations #366
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
Comments
I did some investigating into this and the issue seems to be caused by the following:
Not sure how you can work around this. Changing the equality check in ReactReconciler to a shallowEquals check would work. |
Thanks for looking into this! Does the rewrite in #416 happen to eliminate this issue? |
416 doesn't cache the element, only the final props, since more aggressive shouldComponentUpdate() means render will only fire if it actually needs to rerender, so I would guess it does.? |
Did some testing and and 416 fixes the issue and it does indeed seem to be down to shouldComponentUpdate. Some unscientific testing shows a massive perf increase as well. |
A similar situation is when the
This causes the context from |
Fix link to dev-tools
I did some further testing can confirm that this can be quite an issue if you're using context: What you would expect
What happens
To combat it, in the short term I'm going to try to move all my getChildContext above my connected components. In the long term I guess:
|
One great example of this bug is if you wrap your top level component in connect. As it will wrap the Provider component which has getChildContext, anytime it re-renders (due to a store update which leads to a change in the output of mapStateToProps) the entire tree will re-render unless you have some non-connect shouldComponentUpdate logic. |
Related to #99 and the follow-up issues and pull requests.
I’d like to understand better in which cases we have the behavior described in #365 (comment):
Is just having another component providing context enough to trigger this? Is there any way we can work around this?
The text was updated successfully, but these errors were encountered: