Skip to content

Commit

Permalink
Should not coerce children prop on custom elements to a string. Fixes f…
Browse files Browse the repository at this point in the history
  • Loading branch information
jimfb committed Oct 8, 2015
1 parent 4fb39ce commit a703c37
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/renderers/dom/shared/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,11 @@ ReactDOMComponent.Mixin = {
}
propValue = CSSPropertyOperations.createMarkupForStyles(propValue);
}
var markup = null;
var markup = '';
if (this._tag != null && isCustomComponent(this._tag, props)) {
markup = DOMPropertyOperations.createMarkupForCustomAttribute(propKey, propValue);
if (propKey != 'children' || typeof propValue === 'string' || typeof propValue === 'number') {
markup = DOMPropertyOperations.createMarkupForCustomAttribute(propKey, propValue);
}
} else {
markup = DOMPropertyOperations.createMarkupForProperty(propKey, propValue);
}
Expand Down Expand Up @@ -970,6 +972,9 @@ ReactDOMComponent.Mixin = {
deleteListener(this._rootNodeID, propKey);
}
} else if (isCustomComponent(this._tag, nextProps)) {
if (propKey == 'children' && typeof nextProp !== 'string' && typeof nextProp !== 'number') {
nextProp = null;
}
DOMPropertyOperations.setValueForAttribute(
getNode(this),
propKey,
Expand Down
19 changes: 19 additions & 0 deletions src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,25 @@ describe('ReactDOMComponent', function() {
expect(stubStyle.display).toEqual('');
});

it('should skip child object attribute on web components', function() {
var styles = null;
var container = document.createElement('div');

// Test intial render to null
ReactDOM.render(<my-component children={['foo']} />, container);
expect(container.firstChild.hasAttribute('children')).toBe(false);

ReactDOM.render(<my-component children={'foo'} />, container);
expect(container.firstChild.hasAttribute('children')).toBe(true);

ReactDOM.render(<my-component children={5} />, container);
expect(container.firstChild.hasAttribute('children')).toBe(true);

// Test updates to null
ReactDOM.render(<my-component children={['foo']} />, container);
expect(container.firstChild.hasAttribute('children')).toBe(false);
});

it('should remove attributes', function() {
var container = document.createElement('div');
ReactDOM.render(<img height="17" />, container);
Expand Down

0 comments on commit a703c37

Please sign in to comment.