-
Notifications
You must be signed in to change notification settings - Fork 48
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
ReSub ComponentBase "swallowing" context updates #38
Comments
The problem lies on the current implementation of shouldComponentUpdate |
Ah, so we need to take context into account there. Should be an easy fix. |
Please correct me if I'm wrong: |
My understanding: React doesn't do a deep equalto for shouldcomponentupdate. If you don't provide a shouldcomponentupdate, it defaults to "yes". |
Published 1.0.3 that should address this. Let us know if it doesn't! |
Unfortunately, your specific example shows a weakness in how context works in React. The only fix is to change the class NotWorking extends ComponentBase {
shouldComponentUpdate(nextProps, nextState, nextContext) {
return true;
}
} For a counter example, change class Working extends React.Component {
shouldComponentUpdate(nextProps, nextState, nextContext) {
return !_.isEqual(this.props, nextProps) || !_.isEqual(this.state, nextState) || !_.isEqual(this.context, nextContext);
}
} |
However, if you have no 'middle' components (or they all will update) then there was still a bug. The component that uses context was not re-rendering. PR #40 addressed that. Thanks for pointing that out. |
Be very careful both using and updating context in your application. Best practices for context is described here. An excerpt:
|
It did not solve the issue. It's because of what @ms-markda said here:
So, in order to make it work I'd have to put one of these 'methods/properties' onto NotWorking: static contextTypes = { text: PropTypes.string }; or shouldComponentUpdate() {
return true;
} You'll always get an empty object for context unless you declare it's shape. My 2 cents: PS: @btraut This issue came to surface while using React-Router. But, for instance, Styled-Components also uses it to broadcast changes on theme. I never use context explicitly on my apps, but lots of libraries do. |
It seems that ReSub swallows the context update on some specific use-case.
I'm having trouble using ReSub and React-Router, but I was able to reproduce it with just React.
The repro is the following:
If you'd like to run it on your browser I've made a create-react-app with this code and it is hosted here: https://github.com/degroote22/resubctxbug2
Just clone then npm install then npm start and you should see the following on your browser:
Working: Works Not working:
Thanks for your time 👍
The text was updated successfully, but these errors were encountered: