Merge pull request #5261 from spicyj/dom-null-undef

Bug fixes for createElement mode
This commit is contained in:
Ben Alpert
2015-10-23 15:56:21 -07:00
3 changed files with 25 additions and 3 deletions

View File

@@ -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,

View File

@@ -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) {
@@ -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) {

View File

@@ -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() {