Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should not coerce children prop on custom elements to a string. Fixes #5088 #5093

Merged
merged 1 commit into from
Oct 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/renderers/dom/shared/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Want to put CHILDREN with STYLE. And actually if you rebase, you'll pick up the new one here also using keyof, would be good to have the group of them together

var HTML = keyOf({__html: null});

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down