Skip to content

Commit

Permalink
Merge pull request #5261 from spicyj/dom-null-undef
Browse files Browse the repository at this point in the history
Bug fixes for createElement mode
  • Loading branch information
sophiebits committed Oct 23, 2015
2 parents 939c759 + b447b40 commit 4106251
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/renderers/dom/shared/HTMLDOMPropertyConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ var HTMLDOMPropertyConfig = {
tabIndex: null,
target: null,
title: null,
type: null,
// Setting .type throws on non-<input> tags
type: MUST_USE_ATTRIBUTE,
useMap: null,
value: MUST_USE_PROPERTY | HAS_SIDE_EFFECTS,
width: MUST_USE_ATTRIBUTE,
Expand Down
7 changes: 5 additions & 2 deletions src/renderers/dom/shared/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,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) {
Expand Down Expand Up @@ -967,7 +968,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) {
Expand Down
18 changes: 18 additions & 0 deletions src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 4106251

Please sign in to comment.