Don't set DOM props when switching between unset/undefined/null

This commit is contained in:
Ben Alpert committed 2015-10-23 11:52:29 -07:00
1 parent 4d41cf740a
commit 7221e1b2e9
2 files changed
+23 -2

No files matched your search

@@ -936,7 +936,8 @@ ReactDOMComponent.Mixin = {
var styleUpdates;
for (propKey in lastProps) {
if (nextProps.hasOwnProperty(propKey) ||
!lastProps.hasOwnProperty(propKey)) {
!lastProps.hasOwnProperty(propKey) ||
lastProps[propKey] == null) {
continue;
}
if (propKey === STYLE) {
@@ -966,7 +967,9 @@ ReactDOMComponent.Mixin = {
var lastProp = propKey === STYLE ?
this._previousStyleCopy :
lastProps[propKey];
if (!nextProps.hasOwnProperty(propKey) || nextProp === lastProp) {
if (!nextProps.hasOwnProperty(propKey) ||
nextProp === lastProp ||
nextProp == null && lastProp == null) {
continue;
}
if (propKey === STYLE) {
@@ -426,6 +426,24 @@ describe('ReactDOMComponent', function() {
ReactDOM.render(<button is="test" cowabunga="chevynova"/>, container);
expect(container.firstChild.hasAttribute('cowabunga')).toBe(true);
});
it('should not update when switching between null/undefined', function() {
var container = document.createElement('div');
var node = ReactDOM.render(<div />, container);
var setter = mocks.getMockFunction();
Object.defineProperty(node, 'dir', {
get: function() {},
set: setter,
});
ReactDOM.render(<div dir={null} />, container);
ReactDOM.render(<div dir={undefined} />, container);
ReactDOM.render(<div />, container);
expect(setter.mock.calls.length).toBe(0);
ReactDOM.render(<div dir="ltr" />, container);
expect(setter.mock.calls.length).toBe(1);
});
});
describe('createOpenTagMarkup', function() {