Skip to content

Commit d602f1d

Browse files
jimfbzpao
authored andcommitted
Merge pull request facebook#5093 from jimfb/avoid-children-to-string-coercion
Should not coerce children prop on custom elements to a string. Fixes facebook#5088 (cherry picked from commit a2d26c8)
1 parent c181b82 commit d602f1d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/renderers/dom/shared/ReactDOMComponent.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ var registrationNameModules = ReactBrowserEventEmitter.registrationNameModules;
5151
// For quickly matching children type, to test if can be treated as content.
5252
var CONTENT_TYPES = {'string': true, 'number': true};
5353

54+
var CHILDREN = keyOf({children: null});
5455
var STYLE = keyOf({style: null});
5556
var HTML = keyOf({__html: null});
5657

@@ -675,7 +676,9 @@ ReactDOMComponent.Mixin = {
675676
}
676677
var markup = null;
677678
if (this._tag != null && isCustomComponent(this._tag, props)) {
678-
markup = DOMPropertyOperations.createMarkupForCustomAttribute(propKey, propValue);
679+
if (propKey !== CHILDREN) {
680+
markup = DOMPropertyOperations.createMarkupForCustomAttribute(propKey, propValue);
681+
}
679682
} else {
680683
markup = DOMPropertyOperations.createMarkupForProperty(propKey, propValue);
681684
}
@@ -962,6 +965,9 @@ ReactDOMComponent.Mixin = {
962965
if (!node) {
963966
node = ReactMount.getNode(this._rootNodeID);
964967
}
968+
if (propKey === CHILDREN) {
969+
nextProp = null;
970+
}
965971
DOMPropertyOperations.setValueForAttribute(
966972
node,
967973
propKey,

src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ describe('ReactDOMComponent', function() {
198198
expect(stubStyle.display).toEqual('');
199199
});
200200

201+
it('should skip child object attribute on web components', function() {
202+
var container = document.createElement('div');
203+
204+
// Test intial render to null
205+
ReactDOM.render(<my-component children={['foo']} />, container);
206+
expect(container.firstChild.hasAttribute('children')).toBe(false);
207+
208+
// Test updates to null
209+
ReactDOM.render(<my-component children={['foo']} />, container);
210+
expect(container.firstChild.hasAttribute('children')).toBe(false);
211+
});
212+
201213
it('should remove attributes', function() {
202214
var container = document.createElement('div');
203215
ReactDOM.render(<img height="17" />, container);

0 commit comments

Comments
 (0)