Merge pull request #5320 from drdelambre/overwrite_props

Overwriting of mutated props in constructor
This commit is contained in:
Jim
2015-10-29 18:15:52 -07:00
2 changed files with 36 additions and 1 deletions
@@ -199,7 +199,7 @@ var ReactCompositeComponentMixin = {
// These should be set up in the constructor, but as a convenience for
// simpler class abstractions, we set them up after the fact.
inst.props = publicProps;
inst.props = inst.props || publicProps;
inst.context = publicContext;
inst.refs = emptyObject;
inst.updater = ReactUpdateQueue;
@@ -1241,4 +1241,39 @@ describe('ReactCompositeComponent', function() {
});
it('should not overwrite mutated properties', function() {
class Moo extends React.Component {
render() {
return <span />;
}
}
Moo.defaultProps = { idx: 'moo' };
function Foo(props) {
var _props = { idx: this.constructor.defaultProps.idx + '?' };
React.Component.call(this, _props);
}
Foo.prototype = Object.create(React.Component.prototype, {
constructor: {
value: Foo,
},
});
Foo.prototype.render = function() {
return <span />;
};
Foo.defaultProps = { idx: 'foo' };
class Bar extends Foo {}
Bar.defaultProps = { idx: 'bar' };
var moo = ReactTestUtils.renderIntoDocument(<Moo />);
expect(moo.props.idx).toBe('moo');
var foo = ReactTestUtils.renderIntoDocument(<Foo />);
expect(foo.props.idx).toBe('foo?');
var bar = ReactTestUtils.renderIntoDocument(<Bar />);
expect(bar.props.idx).toBe('bar?');
});
});