mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #5320 from drdelambre/overwrite_props
Overwriting of mutated props in constructor
This commit is contained in:
@@ -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?');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user