Skip to content
Closed
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
39 changes: 21 additions & 18 deletions src/renderers/dom/shared/DOMPropertyOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,30 @@ var DOMPropertyOperations = {
DOMProperty.properties[name] : null;
if (propertyInfo) {
var mutationMethod = propertyInfo.mutationMethod;
var propName = propertyInfo.propertyName;
if (mutationMethod) {
mutationMethod(node, value);
} else if (shouldIgnoreValue(propertyInfo, value)) {
this.deleteValueForProperty(node, name);
return;
} else if (propertyInfo.mustUseProperty) {
// Contrary to `setAttribute`, object properties are properly
// `toString`ed by IE8/9.
node[propertyInfo.propertyName] = value;
} else {
var attributeName = propertyInfo.attributeName;
var namespace = propertyInfo.attributeNamespace;
// `setAttribute` with objects becomes only `[object]` in IE8/9,
// ('' + value) makes it output the correct toString()-value.
if (namespace) {
node.setAttributeNS(namespace, attributeName, '' + value);
} else if (propertyInfo.hasBooleanValue ||
(propertyInfo.hasOverloadedBooleanValue && value === true)) {
node.setAttribute(attributeName, '');
} else if (('' + node[propName]) !== ('' + value)) {
if (shouldIgnoreValue(propertyInfo, value)) {
this.deleteValueForProperty(node, name);
return;
} else if (propertyInfo.mustUseProperty) {
// Contrary to `setAttribute`, object properties are properly
// `toString`ed by IE8/9.
node[propName] = value;
} else {
node.setAttribute(attributeName, '' + value);
var attributeName = propertyInfo.attributeName;
var namespace = propertyInfo.attributeNamespace;
// `setAttribute` with objects becomes only `[object]` in IE8/9,
// ('' + value) makes it output the correct toString()-value.
if (namespace) {
node.setAttributeNS(namespace, attributeName, '' + value);
} else if (propertyInfo.hasBooleanValue ||
(propertyInfo.hasOverloadedBooleanValue && value === true)) {
node.setAttribute(attributeName, '');
} else {
node.setAttribute(attributeName, '' + value);
}
}
}
} else if (DOMProperty.isCustomAttribute(name)) {
Expand Down
11 changes: 4 additions & 7 deletions src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,11 @@ describe('ReactDOMComponent', () => {
expect(node.removeAttribute.mock.calls.length).toBe(1);

ReactDOM.render(<div id="" />, container);
expect(node.setAttribute.mock.calls.length).toBe(2);
expect(node.setAttribute.mock.calls.length).toBe(1);
expect(node.removeAttribute.mock.calls.length).toBe(1);

ReactDOM.render(<div />, container);
expect(node.setAttribute.mock.calls.length).toBe(2);
expect(node.setAttribute.mock.calls.length).toBe(1);
expect(node.removeAttribute.mock.calls.length).toBe(2);
});

Expand All @@ -535,9 +535,6 @@ describe('ReactDOMComponent', () => {
ReactDOM.render(<div value="foo" />, container);
expect(nodeValueSetter.mock.calls.length).toBe(1);

ReactDOM.render(<div value="foo" />, container);
expect(nodeValueSetter.mock.calls.length).toBe(1);

ReactDOM.render(<div />, container);
expect(nodeValueSetter.mock.calls.length).toBe(1);

Expand Down Expand Up @@ -574,10 +571,10 @@ describe('ReactDOMComponent', () => {
expect(nodeValueSetter.mock.calls.length).toBe(1);

ReactDOM.render(<div checked={false} />, container);
expect(nodeValueSetter.mock.calls.length).toBe(2);
expect(nodeValueSetter.mock.calls.length).toBe(1);

ReactDOM.render(<div checked={true} />, container);
expect(nodeValueSetter.mock.calls.length).toBe(3);
expect(nodeValueSetter.mock.calls.length).toBe(2);
});

it('should ignore attribute whitelist for elements with the "is: attribute', () => {
Expand Down