Make sure cloneElement() supports prototype-less config (#6878)

This brings createElement() fix from #6855 to cloneElement().
(cherry picked from commit e822cbd183)
This commit is contained in:
Dan Abramov
2016-06-14 15:49:48 -07:00
committed by Paul O’Shannessy
parent c8b2a3dc13
commit 31ba751d2e
2 changed files with 6 additions and 1 deletions
@@ -311,7 +311,7 @@ ReactElement.cloneElement = function(element, config, children) {
defaultProps = element.type.defaultProps;
}
for (propName in config) {
if (config.hasOwnProperty(propName) &&
if (hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS.hasOwnProperty(propName)) {
if (config[propName] === undefined && defaultProps !== undefined) {
// Resolve default props
@@ -78,6 +78,11 @@ describe('ReactElementClone', function() {
);
});
it('does not fail if config has no prototype', function() {
var config = Object.create(null, {foo: {value: 1, enumerable: true}});
React.cloneElement(<div />, config);
});
it('should keep the original ref if it is not overridden', function() {
var Grandparent = React.createClass({
render: function() {