Don't skip reconcilation if context differs

This commit is contained in:
Jim
2015-07-10 17:50:37 -07:00
parent 52ad6bc61a
commit 9baaeec21d
3 changed files with 73 additions and 6 deletions
@@ -66,8 +66,8 @@ var ReactReconciler = {
) {
var prevElement = internalInstance._currentElement;
if (nextElement === prevElement &&
nextElement._owner != null
// TODO: Shouldn't we need to do this: `&& context === internalInstance._context`
nextElement._owner != null &&
context === internalInstance._context
) {
// Since elements are immutable after the owner is rendered,
// we can do a cheap identity compare here to determine if this is a
@@ -667,6 +667,68 @@ describe('ReactCompositeComponent', function() {
reactComponentExpect(childInstance).scalarContextEqual({foo: 'bar', flag: true});
});
it('should pass context when re-rendered for static child within a composite component', function() {
var Parent = React.createClass({
childContextTypes: {
flag: ReactPropTypes.bool,
},
getChildContext() {
return {
flag: this.state.flag,
};
},
getInitialState: function() {
return {
flag: true,
};
},
render() {
return <div>{this.props.children}</div>;
},
});
var Child = React.createClass({
contextTypes: {
flag: ReactPropTypes.bool,
},
render: function() {
return <div />;
},
});
var Wrapper = React.createClass({
render() {
return (
<Parent ref="parent">
<Child ref="child" />
</Parent>
);
},
});
var wrapper = ReactTestUtils.renderIntoDocument(
<Wrapper />
);
expect(wrapper.refs.parent.state.flag).toEqual(true);
reactComponentExpect(wrapper.refs.child).scalarContextEqual({flag: true});
// We update <Parent /> while <Child /> is still a static prop relative to this update
wrapper.refs.parent.setState({flag: false});
expect(console.error.argsForCall.length).toBe(0);
expect(wrapper.refs.parent.state.flag).toEqual(false);
reactComponentExpect(wrapper.refs.child).scalarContextEqual({flag: false});
});
it('should pass context transitively', function() {
var childInstance = null;
var grandchildInstance = null;
@@ -433,10 +433,15 @@ describe('ReactUpdates', function() {
root = ReactTestUtils.renderIntoDocument(root);
function expectUpdates(desiredWillUpdates, desiredDidUpdates) {
expect(willUpdates).toEqual(desiredWillUpdates);
expect(didUpdates).toEqual(desiredDidUpdates);
willUpdates.length = 0;
didUpdates.length = 0;
var i;
for (i = 0; i < desiredWillUpdates; i++) {
expect(willUpdates).toContain(desiredWillUpdates[i]);
}
for (i = 0; i < desiredDidUpdates; i++) {
expect(didUpdates).toContain(desiredDidUpdates[i]);
}
willUpdates = [];
didUpdates = [];
}
function triggerUpdate(c) {