Skip to content

Commit

Permalink
Don't skip reconcilation if context differs
Browse files Browse the repository at this point in the history
  • Loading branch information
jimfb committed Jul 13, 2015
1 parent 52ad6bc commit 9baaeec
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/renderers/shared/reconciler/ReactReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 9 additions & 4 deletions src/renderers/shared/reconciler/__tests__/ReactUpdates-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9baaeec

Please sign in to comment.