From 0ebc7b60e10c1fcbdf7847a81bd800f7d11ffb90 Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Tue, 5 Jan 2016 15:08:15 -0800 Subject: [PATCH] Revert "Merge pull request #5689 from jimfb/cleanup-5151" This reverts commit 067547c1d156ea9527dc8f4b4036d2824b651790, reversing changes made to 102cd291899f9942a76c40a0e78920a6fe544dc1. --- src/renderers/dom/shared/ReactDOMComponent.js | 6 ++++-- .../dom/shared/ReactDOMEmptyComponent.js | 5 +++-- .../dom/shared/ReactDOMTextComponent.js | 7 +++++-- .../reconciler/ReactCompositeComponent.js | 17 ++++++++++++++--- .../shared/reconciler/ReactReconciler.js | 8 ++++++++ .../reconciler/ReactSimpleEmptyComponent.js | 3 +++ .../reconciler/instantiateReactComponent.js | 1 + src/test/ReactTestUtils.js | 4 ++++ 8 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/renderers/dom/shared/ReactDOMComponent.js b/src/renderers/dom/shared/ReactDOMComponent.js index fde61e9b5e..e5098b83f3 100644 --- a/src/renderers/dom/shared/ReactDOMComponent.js +++ b/src/renderers/dom/shared/ReactDOMComponent.js @@ -1009,6 +1009,10 @@ ReactDOMComponent.Mixin = { } }, + getNativeNode: function() { + return getNode(this); + }, + /** * Destroys all event registrations for this instance. Does not remove from * the DOM. That must be done by the parent. @@ -1053,7 +1057,6 @@ ReactDOMComponent.Mixin = { break; } - var nativeNode = getNode(this); this.unmountChildren(); ReactDOMComponentTree.uncacheNode(this); EventPluginHub.deleteAllListeners(this); @@ -1061,7 +1064,6 @@ ReactDOMComponent.Mixin = { this._rootNodeID = null; this._domID = null; this._wrapperState = null; - return nativeNode; }, getPublicInstance: function() { diff --git a/src/renderers/dom/shared/ReactDOMEmptyComponent.js b/src/renderers/dom/shared/ReactDOMEmptyComponent.js index f87015b029..e07c44781e 100644 --- a/src/renderers/dom/shared/ReactDOMEmptyComponent.js +++ b/src/renderers/dom/shared/ReactDOMEmptyComponent.js @@ -57,10 +57,11 @@ assign(ReactDOMEmptyComponent.prototype, { }, receiveComponent: function() { }, + getNativeNode: function() { + return ReactDOMComponentTree.getNodeFromInstance(this); + }, unmountComponent: function() { - var node = ReactDOMComponentTree.getNodeFromInstance(this); ReactDOMComponentTree.uncacheNode(this); - return node; }, }); diff --git a/src/renderers/dom/shared/ReactDOMTextComponent.js b/src/renderers/dom/shared/ReactDOMTextComponent.js index 771792b33d..63d022bf33 100644 --- a/src/renderers/dom/shared/ReactDOMTextComponent.js +++ b/src/renderers/dom/shared/ReactDOMTextComponent.js @@ -137,10 +137,13 @@ assign(ReactDOMTextComponent.prototype, { } } }, + + getNativeNode: function() { + return getNode(this); + }, + unmountComponent: function() { - var node = getNode(this); ReactDOMComponentTree.uncacheNode(this); - return node; }, }); diff --git a/src/renderers/shared/reconciler/ReactCompositeComponent.js b/src/renderers/shared/reconciler/ReactCompositeComponent.js index ac85a8ddf7..3c5da98157 100644 --- a/src/renderers/shared/reconciler/ReactCompositeComponent.js +++ b/src/renderers/shared/reconciler/ReactCompositeComponent.js @@ -370,6 +370,10 @@ var ReactCompositeComponentMixin = { return markup; }, + getNativeNode: function() { + return ReactReconciler.getNativeNode(this._renderedComponent); + }, + /** * Releases any resources allocated by `mountComponent`. * @@ -384,7 +388,7 @@ var ReactCompositeComponentMixin = { } if (this._renderedComponent) { - var unmountedNativeNode = ReactReconciler.unmountComponent(this._renderedComponent); + ReactReconciler.unmountComponent(this._renderedComponent); this._renderedNodeType = null; this._renderedComponent = null; this._instance = null; @@ -415,7 +419,6 @@ var ReactCompositeComponentMixin = { // TODO: inst.props = null; // TODO: inst.state = null; // TODO: inst.context = null; - return unmountedNativeNode; }, /** @@ -803,7 +806,15 @@ var ReactCompositeComponentMixin = { this._processChildContext(context) ); } else { - var oldNativeNode = ReactReconciler.unmountComponent(prevComponentInstance); + // TODO: This is currently necessary due to the unfortunate caching + // that ReactMount does which makes it exceedingly difficult to unmount + // a set of siblings without accidentally repopulating the node cache (see + // #5151). Once ReactMount no longer stores the nodes by ID, this method + // can go away. + var oldNativeNode = ReactReconciler.getNativeNode(prevComponentInstance); + + ReactReconciler.unmountComponent(prevComponentInstance); + this._renderedNodeType = ReactNodeTypes.getType(nextRenderedElement); this._renderedComponent = this._instantiateReactComponent( nextRenderedElement diff --git a/src/renderers/shared/reconciler/ReactReconciler.js b/src/renderers/shared/reconciler/ReactReconciler.js index 31c167e9fc..4e1a1d3934 100644 --- a/src/renderers/shared/reconciler/ReactReconciler.js +++ b/src/renderers/shared/reconciler/ReactReconciler.js @@ -54,6 +54,14 @@ var ReactReconciler = { return markup; }, + /** + * Returns a value that can be passed to + * ReactComponentEnvironment.replaceNodeWithMarkup. + */ + getNativeNode: function(internalInstance) { + return internalInstance.getNativeNode(); + }, + /** * Releases any resources allocated by `mountComponent`. * diff --git a/src/renderers/shared/reconciler/ReactSimpleEmptyComponent.js b/src/renderers/shared/reconciler/ReactSimpleEmptyComponent.js index 8fe0a209b1..2a886be3be 100644 --- a/src/renderers/shared/reconciler/ReactSimpleEmptyComponent.js +++ b/src/renderers/shared/reconciler/ReactSimpleEmptyComponent.js @@ -38,6 +38,9 @@ assign(ReactSimpleEmptyComponent.prototype, { }, receiveComponent: function() { }, + getNativeNode: function() { + return ReactReconciler.getNativeNode(this._renderedComponent); + }, unmountComponent: function() { ReactReconciler.unmountComponent(this._renderedComponent); this._renderedComponent = null; diff --git a/src/renderers/shared/reconciler/instantiateReactComponent.js b/src/renderers/shared/reconciler/instantiateReactComponent.js index eabe39972e..4ddf8e861f 100644 --- a/src/renderers/shared/reconciler/instantiateReactComponent.js +++ b/src/renderers/shared/reconciler/instantiateReactComponent.js @@ -104,6 +104,7 @@ function instantiateReactComponent(node) { typeof instance.construct === 'function' && typeof instance.mountComponent === 'function' && typeof instance.receiveComponent === 'function' && + typeof instance.getNativeNode === 'function' && typeof instance.unmountComponent === 'function', 'Only React Components can be mounted.' ); diff --git a/src/test/ReactTestUtils.js b/src/test/ReactTestUtils.js index b1a525c92a..0855f6da26 100644 --- a/src/test/ReactTestUtils.js +++ b/src/test/ReactTestUtils.js @@ -381,6 +381,10 @@ NoopInternalComponent.prototype = { this._currentElement = element; }, + getNativeNode: function() { + return undefined; + }, + unmountComponent: function() { },