Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably just make this expect(willUpdates.slice()).toEqual(desiredWillUpdates). That will create a new array so that emptying out the original should be ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would fix the issue from jestjs/jest#429 (I solved that by assigning a new empty array to the variable), but there is also the issue that the lifecycle gets called more often in dev, so the arrays will not be equal anymore due to #3516. We now just verify that every element of desiredWillUpdates dose appear in willUpdates.

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