mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #5093 from jimfb/avoid-children-to-string-coercion
Should not coerce children prop on custom elements to a string. Fixes #5088
This commit is contained in:
@@ -53,6 +53,7 @@ var registrationNameModules = EventPluginRegistry.registrationNameModules;
|
||||
// For quickly matching children type, to test if can be treated as content.
|
||||
var CONTENT_TYPES = {'string': true, 'number': true};
|
||||
|
||||
var CHILDREN = keyOf({children: null});
|
||||
var STYLE = keyOf({style: null});
|
||||
var HTML = keyOf({__html: null});
|
||||
|
||||
@@ -744,7 +745,9 @@ ReactDOMComponent.Mixin = {
|
||||
}
|
||||
var markup = null;
|
||||
if (this._tag != null && isCustomComponent(this._tag, props)) {
|
||||
markup = DOMPropertyOperations.createMarkupForCustomAttribute(propKey, propValue);
|
||||
if (propKey !== CHILDREN) {
|
||||
markup = DOMPropertyOperations.createMarkupForCustomAttribute(propKey, propValue);
|
||||
}
|
||||
} else {
|
||||
markup = DOMPropertyOperations.createMarkupForProperty(propKey, propValue);
|
||||
}
|
||||
@@ -1015,6 +1018,9 @@ ReactDOMComponent.Mixin = {
|
||||
deleteListener(this._rootNodeID, propKey);
|
||||
}
|
||||
} else if (isCustomComponent(this._tag, nextProps)) {
|
||||
if (propKey === CHILDREN) {
|
||||
nextProp = null;
|
||||
}
|
||||
DOMPropertyOperations.setValueForAttribute(
|
||||
getNode(this),
|
||||
propKey,
|
||||
|
||||
@@ -237,6 +237,18 @@ describe('ReactDOMComponent', function() {
|
||||
expect(stubStyle.display).toEqual('');
|
||||
});
|
||||
|
||||
it('should skip child object attribute on web components', function() {
|
||||
var container = document.createElement('div');
|
||||
|
||||
// Test intial render to null
|
||||
ReactDOM.render(<my-component children={['foo']} />, container);
|
||||
expect(container.firstChild.hasAttribute('children')).toBe(false);
|
||||
|
||||
// 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);
|
||||
|
||||
Reference in New Issue
Block a user