@samitouri / QOS-React-2 / commits / 0ebc7b60e1

Revert "Merge pull request #5689 from jimfb/cleanup-5151"

This reverts commit 067547c1d156ea9527dc8f4b4036d2824b651790, reversing changes made to 102cd291899f9942a76c40a0e78920a6fe544dc1.

Ben Alpert committed Jan 5, 2016 at 15:08 UTC 0ebc7b60e10c1fcbdf7847a81bd800f7d11ffb90
8 files changed +42 -9
src/renderers/dom/shared/ReactDOMComponent.js
+4 -2
@@ -1009,6 +1009,10 @@ ReactDOMComponent.Mixin = {
1009 }
1010 },
1011
1012 + getNativeNode: function() {
1013 + return getNode(this);
1014 + },
1015 +
1016 /**
1017 * Destroys all event registrations for this instance. Does not remove from
1018 * the DOM. That must be done by the parent.
@@ -1053,7 +1057,6 @@ ReactDOMComponent.Mixin = {
1057 break;
1058 }
1059
1056 - var nativeNode = getNode(this);
1060 this.unmountChildren();
1061 ReactDOMComponentTree.uncacheNode(this);
1062 EventPluginHub.deleteAllListeners(this);
@@ -1061,7 +1064,6 @@ ReactDOMComponent.Mixin = {
1064 this._rootNodeID = null;
1065 this._domID = null;
1066 this._wrapperState = null;
1064 - return nativeNode;
1067 },
1068
1069 getPublicInstance: function() {
src/renderers/dom/shared/ReactDOMEmptyComponent.js
+3 -2
@@ -57,10 +57,11 @@ assign(ReactDOMEmptyComponent.prototype, {
57 },
58 receiveComponent: function() {
59 },
60 + getNativeNode: function() {
61 + return ReactDOMComponentTree.getNodeFromInstance(this);
62 + },
63 unmountComponent: function() {
61 - var node = ReactDOMComponentTree.getNodeFromInstance(this);
64 ReactDOMComponentTree.uncacheNode(this);
63 - return node;
65 },
66 });
67
src/renderers/dom/shared/ReactDOMTextComponent.js
+5 -2
@@ -137,10 +137,13 @@ assign(ReactDOMTextComponent.prototype, {
137 }
138 }
139 },
140 +
141 + getNativeNode: function() {
142 + return getNode(this);
143 + },
144 +
145 unmountComponent: function() {
141 - var node = getNode(this);
146 ReactDOMComponentTree.uncacheNode(this);
143 - return node;
147 },
148
149 });
src/renderers/shared/reconciler/ReactCompositeComponent.js
+14 -3
@@ -370,6 +370,10 @@ var ReactCompositeComponentMixin = {
370 return markup;
371 },
372
373 + getNativeNode: function() {
374 + return ReactReconciler.getNativeNode(this._renderedComponent);
375 + },
376 +
377 /**
378 * Releases any resources allocated by `mountComponent`.
379 *
@@ -384,7 +388,7 @@ var ReactCompositeComponentMixin = {
388 }
389
390 if (this._renderedComponent) {
387 - var unmountedNativeNode = ReactReconciler.unmountComponent(this._renderedComponent);
391 + ReactReconciler.unmountComponent(this._renderedComponent);
392 this._renderedNodeType = null;
393 this._renderedComponent = null;
394 this._instance = null;
@@ -415,7 +419,6 @@ var ReactCompositeComponentMixin = {
419 // TODO: inst.props = null;
420 // TODO: inst.state = null;
421 // TODO: inst.context = null;
418 - return unmountedNativeNode;
422 },
423
424 /**
@@ -803,7 +806,15 @@ var ReactCompositeComponentMixin = {
806 this._processChildContext(context)
807 );
808 } else {
806 - var oldNativeNode = ReactReconciler.unmountComponent(prevComponentInstance);
809 + // TODO: This is currently necessary due to the unfortunate caching
810 + // that ReactMount does which makes it exceedingly difficult to unmount
811 + // a set of siblings without accidentally repopulating the node cache (see
812 + // #5151). Once ReactMount no longer stores the nodes by ID, this method
813 + // can go away.
814 + var oldNativeNode = ReactReconciler.getNativeNode(prevComponentInstance);
815 +
816 + ReactReconciler.unmountComponent(prevComponentInstance);
817 +
818 this._renderedNodeType = ReactNodeTypes.getType(nextRenderedElement);
819 this._renderedComponent = this._instantiateReactComponent(
820 nextRenderedElement
src/renderers/shared/reconciler/ReactReconciler.js
+8
@@ -54,6 +54,14 @@ var ReactReconciler = {
54 return markup;
55 },
56
57 + /**
58 + * Returns a value that can be passed to
59 + * ReactComponentEnvironment.replaceNodeWithMarkup.
60 + */
61 + getNativeNode: function(internalInstance) {
62 + return internalInstance.getNativeNode();
63 + },
64 +
65 /**
66 * Releases any resources allocated by `mountComponent`.
67 *
src/renderers/shared/reconciler/ReactSimpleEmptyComponent.js
+3
@@ -38,6 +38,9 @@ assign(ReactSimpleEmptyComponent.prototype, {
38 },
39 receiveComponent: function() {
40 },
41 + getNativeNode: function() {
42 + return ReactReconciler.getNativeNode(this._renderedComponent);
43 + },
44 unmountComponent: function() {
45 ReactReconciler.unmountComponent(this._renderedComponent);
46 this._renderedComponent = null;
src/renderers/shared/reconciler/instantiateReactComponent.js
+1
@@ -104,6 +104,7 @@ function instantiateReactComponent(node) {
104 typeof instance.construct === 'function' &&
105 typeof instance.mountComponent === 'function' &&
106 typeof instance.receiveComponent === 'function' &&
107 + typeof instance.getNativeNode === 'function' &&
108 typeof instance.unmountComponent === 'function',
109 'Only React Components can be mounted.'
110 );
src/test/ReactTestUtils.js
+4
@@ -381,6 +381,10 @@ NoopInternalComponent.prototype = {
381 this._currentElement = element;
382 },
383
384 + getNativeNode: function() {
385 + return undefined;
386 + },
387 +
388 unmountComponent: function() {
389 },
390