Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bailout if the element and the context is unchanged properly #7819

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 2 additions & 1 deletion src/renderers/shared/stack/reconciler/ReactReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

var ReactRef = require('ReactRef');
var ReactInstrumentation = require('ReactInstrumentation');
var shallowEqual = require('shallowEqual');

var warning = require('warning');

Expand Down Expand Up @@ -127,7 +128,7 @@ var ReactReconciler = {
var prevElement = internalInstance._currentElement;

if (nextElement === prevElement &&
context === internalInstance._context
shallowEqual(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 @@ -610,6 +610,40 @@ describe('ReactCompositeComponent', () => {
expect(childRenders).toBe(1);
});

it('should skip update when rerendering element in container and the context is unchanged', () => {
var context = { foo: 'bar' };

class Parent extends React.Component {
static childContextTypes = {
foo: ReactPropTypes.string,
};

getChildContext() {
return context;
}

render() {
return <div>{this.props.children}</div>;
}
}

var childRenders = 0;

class Child extends React.Component {
render() {
childRenders++;
return <div />;
}
}

var container = document.createElement('div');
var child = <Child />;

ReactDOM.render(<Parent>{child}</Parent>, container);
ReactDOM.render(<Parent>{child}</Parent>, container);
expect(childRenders).toBe(1);
});

it('should pass context when re-rendered for static child', () => {
var parentInstance = null;
var childInstance = null;
Expand Down