diff --git a/src/renderers/shared/reconciler/ReactChildReconciler.js b/src/renderers/shared/reconciler/ReactChildReconciler.js
index fdcd80633f..2b2a63a666 100644
--- a/src/renderers/shared/reconciler/ReactChildReconciler.js
+++ b/src/renderers/shared/reconciler/ReactChildReconciler.js
@@ -90,7 +90,8 @@ var ReactChildReconciler = {
var prevChild = prevChildren && prevChildren[name];
var prevElement = prevChild && prevChild._currentElement;
var nextElement = nextChildren[name];
- if (shouldUpdateReactComponent(prevElement, nextElement)) {
+ if (prevChild != null &&
+ shouldUpdateReactComponent(prevElement, nextElement)) {
ReactReconciler.receiveComponent(
prevChild, nextElement, transaction, context
);
diff --git a/src/renderers/shared/reconciler/__tests__/ReactEmptyComponent-test.js b/src/renderers/shared/reconciler/__tests__/ReactEmptyComponent-test.js
index b4f056cae0..527826b8ea 100644
--- a/src/renderers/shared/reconciler/__tests__/ReactEmptyComponent-test.js
+++ b/src/renderers/shared/reconciler/__tests__/ReactEmptyComponent-test.js
@@ -265,4 +265,25 @@ describe('ReactEmptyComponent', function() {
ReactTestUtils.renderIntoDocument();
}).not.toThrow();
});
+
+ it('preserves the dom node during updates', function() {
+ var Empty = React.createClass({
+ render: function() {
+ return null;
+ },
+ });
+
+ var container = document.createElement('div');
+
+ ReactDOM.render(, container);
+ var noscript1 = container.firstChild;
+ expect(noscript1.tagName).toBe('NOSCRIPT');
+
+ // This update shouldn't create a DOM node
+ ReactDOM.render(, container);
+ var noscript2 = container.firstChild;
+ expect(noscript2.tagName).toBe('NOSCRIPT');
+
+ expect(noscript1).toBe(noscript2);
+ });
});
diff --git a/src/renderers/shared/reconciler/shouldUpdateReactComponent.js b/src/renderers/shared/reconciler/shouldUpdateReactComponent.js
index f80cdde268..3ffb75625e 100644
--- a/src/renderers/shared/reconciler/shouldUpdateReactComponent.js
+++ b/src/renderers/shared/reconciler/shouldUpdateReactComponent.js
@@ -24,18 +24,22 @@
* @protected
*/
function shouldUpdateReactComponent(prevElement, nextElement) {
- if (prevElement != null && nextElement != null) {
- var prevType = typeof prevElement;
- var nextType = typeof nextElement;
- if (prevType === 'string' || prevType === 'number') {
- return (nextType === 'string' || nextType === 'number');
- } else {
- return (
- nextType === 'object' &&
- prevElement.type === nextElement.type &&
- prevElement.key === nextElement.key
- );
- }
+ var prevEmpty = prevElement === null || prevElement === false;
+ var nextEmpty = nextElement === null || nextElement === false;
+ if (prevEmpty || nextEmpty) {
+ return prevEmpty === nextEmpty;
+ }
+
+ var prevType = typeof prevElement;
+ var nextType = typeof nextElement;
+ if (prevType === 'string' || prevType === 'number') {
+ return (nextType === 'string' || nextType === 'number');
+ } else {
+ return (
+ nextType === 'object' &&
+ prevElement.type === nextElement.type &&
+ prevElement.key === nextElement.key
+ );
}
return false;
}