Don't set DOM props when switching between unset/undefined/null
Ben Alpert committed
Oct 23, 2015 at 11:51 UTC
7221e1b2e9369f3655fc68586f59cb67cf0f3d0e
2 files changed
+23
-2
src/renderers/dom/shared/ReactDOMComponent.js
+5
-2
@@ -936,7 +936,8 @@ ReactDOMComponent.Mixin = {
936
var styleUpdates;
937
for (propKey in lastProps) {
938
if (nextProps.hasOwnProperty(propKey) ||
939
- !lastProps.hasOwnProperty(propKey)) {
939
+ !lastProps.hasOwnProperty(propKey) ||
940
+ lastProps[propKey] == null) {
941
continue;
942
}
943
if (propKey === STYLE) {
@@ -966,7 +967,9 @@ ReactDOMComponent.Mixin = {
967
var lastProp = propKey === STYLE ?
968
this._previousStyleCopy :
969
lastProps[propKey];
969
- if (!nextProps.hasOwnProperty(propKey) || nextProp === lastProp) {
970
+ if (!nextProps.hasOwnProperty(propKey) ||
971
+ nextProp === lastProp ||
972
+ nextProp == null && lastProp == null) {
973
continue;
974
}
975
if (propKey === STYLE) {
src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
+18
@@ -426,6 +426,24 @@ describe('ReactDOMComponent', function() {
426
ReactDOM.render(<button is="test" cowabunga="chevynova"/>, container);
427
expect(container.firstChild.hasAttribute('cowabunga')).toBe(true);
428
});
429
+
430
+ it('should not update when switching between null/undefined', function() {
431
+ var container = document.createElement('div');
432
+ var node = ReactDOM.render(<div />, container);
433
+
434
+ var setter = mocks.getMockFunction();
435
+ Object.defineProperty(node, 'dir', {
436
+ get: function() {},
437
+ set: setter,
438
+ });
439
+
440
+ ReactDOM.render(<div dir={null} />, container);
441
+ ReactDOM.render(<div dir={undefined} />, container);
442
+ ReactDOM.render(<div />, container);
443
+ expect(setter.mock.calls.length).toBe(0);
444
+ ReactDOM.render(<div dir="ltr" />, container);
445
+ expect(setter.mock.calls.length).toBe(1);
446
+ });
447
});
448
449
describe('createOpenTagMarkup', function() {