Skip to content

Commit

Permalink
Update shallowCompare to accept nextContext (#6661)
Browse files Browse the repository at this point in the history
* Update shallowCompare to accept nextContext

Across our application we are using immutable objects as properties and thus using shallowCompare for all our {{shouldComponentUpdate}}.  Because of this children with contextTypes don't get updates when the context on the parent changes.  Adding an additional comparison for context (when it is provided) fixes this problem.

* Remove the undefined check

* Add nextContext
  • Loading branch information
tony99nyr authored and jimfb committed May 17, 2016
1 parent 7f08961 commit 8ea1cf4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/addons/ReactComponentWithPureRenderMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ var shallowCompare = require('shallowCompare');
* See https://facebook.github.io/react/docs/pure-render-mixin.html
*/
var ReactComponentWithPureRenderMixin = {
shouldComponentUpdate: function(nextProps, nextState) {
return shallowCompare(this, nextProps, nextState);
shouldComponentUpdate: function(nextProps, nextState, nextContext) {
return shallowCompare(this, nextProps, nextState, nextContext);
},
};

Expand Down
5 changes: 3 additions & 2 deletions src/addons/shallowCompare.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ var shallowEqual = require('shallowEqual');
* See ReactComponentWithPureRenderMixin
* See also https://facebook.github.io/react/docs/shallow-compare.html
*/
function shallowCompare(instance, nextProps, nextState) {
function shallowCompare(instance, nextProps, nextState, nextContext) {
return (
!shallowEqual(instance.props, nextProps) ||
!shallowEqual(instance.state, nextState)
!shallowEqual(instance.state, nextState) ||
!shallowEqual(instance.context, nextContext)
);
}

Expand Down

0 comments on commit 8ea1cf4

Please sign in to comment.