From 3af73834d932bb5b6c13e7e5eb60bc2c0718c2da Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Thu, 18 Jun 2015 09:19:40 -0700 Subject: [PATCH] Remove currentlyUnmountingComponent This was used for any invariant that was subsequently removed. It turns out that this is completely unnecessary now. Any setState calls will enqueue and update and the component added to the update queue. However, since the pending fields are reset after componentWillUnmount, any update will still be ignored. --- .../shared/reconciler/ReactCompositeComponent.js | 10 +++------- src/renderers/shared/reconciler/ReactLifeCycle.js | 6 ------ src/renderers/shared/reconciler/ReactUpdateQueue.js | 4 ---- .../__tests__/ReactComponentLifeCycle-test.js | 7 ------- 4 files changed, 3 insertions(+), 24 deletions(-) diff --git a/src/renderers/shared/reconciler/ReactCompositeComponent.js b/src/renderers/shared/reconciler/ReactCompositeComponent.js index c95a58593d..531409eac1 100644 --- a/src/renderers/shared/reconciler/ReactCompositeComponent.js +++ b/src/renderers/shared/reconciler/ReactCompositeComponent.js @@ -265,19 +265,15 @@ var ReactCompositeComponentMixin = { var inst = this._instance; if (inst.componentWillUnmount) { - var previouslyUnmounting = ReactLifeCycle.currentlyUnmountingInstance; - ReactLifeCycle.currentlyUnmountingInstance = this; - try { - inst.componentWillUnmount(); - } finally { - ReactLifeCycle.currentlyUnmountingInstance = previouslyUnmounting; - } + inst.componentWillUnmount(); } ReactReconciler.unmountComponent(this._renderedComponent); this._renderedComponent = null; // Reset pending fields + // Even if this component is scheduled for another update in ReactUpdates, + // it would still be ignored because these fields are reset. this._pendingStateQueue = null; this._pendingReplaceState = false; this._pendingForceUpdate = false; diff --git a/src/renderers/shared/reconciler/ReactLifeCycle.js b/src/renderers/shared/reconciler/ReactLifeCycle.js index e015c6b1ab..20f4386bfa 100644 --- a/src/renderers/shared/reconciler/ReactLifeCycle.js +++ b/src/renderers/shared/reconciler/ReactLifeCycle.js @@ -20,16 +20,10 @@ * currentlyMountingInstance: During the construction phase, it is not possible * to trigger an update since the instance is not fully mounted yet. However, we * currently allow this as a convenience for mutating the initial state. - * - * currentlyUnmountingInstance: During the unmounting phase, the instance is - * still mounted and can therefore schedule an update. However, this is not - * recommended and probably an error since it's about to be unmounted. - * Therefore we still want to trigger in an error for that case. */ var ReactLifeCycle = { currentlyMountingInstance: null, - currentlyUnmountingInstance: null, }; module.exports = ReactLifeCycle; diff --git a/src/renderers/shared/reconciler/ReactUpdateQueue.js b/src/renderers/shared/reconciler/ReactUpdateQueue.js index 1d5172de51..75d7a33d17 100644 --- a/src/renderers/shared/reconciler/ReactUpdateQueue.js +++ b/src/renderers/shared/reconciler/ReactUpdateQueue.js @@ -61,10 +61,6 @@ function getInternalInstanceReadyForUpdate(publicInstance, callerName) { return null; } - if (internalInstance === ReactLifeCycle.currentlyUnmountingInstance) { - return null; - } - return internalInstance; } diff --git a/src/renderers/shared/reconciler/__tests__/ReactComponentLifeCycle-test.js b/src/renderers/shared/reconciler/__tests__/ReactComponentLifeCycle-test.js index a43f0a7530..1324d14031 100644 --- a/src/renderers/shared/reconciler/__tests__/ReactComponentLifeCycle-test.js +++ b/src/renderers/shared/reconciler/__tests__/ReactComponentLifeCycle-test.js @@ -89,10 +89,6 @@ var CompositeComponentLifeCycle = keyMirror({ * receiving new props. */ MOUNTING: null, - /** - * Unmounted components are inactive and cannot receive new props. - */ - UNMOUNTING: null, }); function getCompositeLifeCycle(instance) { @@ -103,9 +99,6 @@ function getCompositeLifeCycle(instance) { if (ReactLifeCycle.currentlyMountingInstance === internalInstance) { return CompositeComponentLifeCycle.MOUNTING; } - if (ReactLifeCycle.currentlyUnmountingInstance === internalInstance) { - return CompositeComponentLifeCycle.UNMOUNTING; - } return null; }