From 8ea1cf4ee0f5315c4190a9e67e15f0f7404cb0cf Mon Sep 17 00:00:00 2001 From: Tony Rossi Date: Tue, 17 May 2016 19:50:23 -0400 Subject: [PATCH] Update shallowCompare to accept nextContext (#6661) * 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 --- src/addons/ReactComponentWithPureRenderMixin.js | 4 ++-- src/addons/shallowCompare.js | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/addons/ReactComponentWithPureRenderMixin.js b/src/addons/ReactComponentWithPureRenderMixin.js index cf00d7cb3d..3354185257 100644 --- a/src/addons/ReactComponentWithPureRenderMixin.js +++ b/src/addons/ReactComponentWithPureRenderMixin.js @@ -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); }, }; diff --git a/src/addons/shallowCompare.js b/src/addons/shallowCompare.js index a6b7a1095d..4e25aa7654 100644 --- a/src/addons/shallowCompare.js +++ b/src/addons/shallowCompare.js @@ -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) ); }