From bf24dc33f7ef77a0b768f0c6885923d79184a99f Mon Sep 17 00:00:00 2001 From: John Watson Date: Wed, 4 Dec 2013 17:47:11 -0800 Subject: [PATCH] Separate replaceState invariant violations It'd be nice if we knew which error we were hitting when this invariant hit. --- src/core/ReactCompositeComponent.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/ReactCompositeComponent.js b/src/core/ReactCompositeComponent.js index 9462757d94..6376cb8af2 100644 --- a/src/core/ReactCompositeComponent.js +++ b/src/core/ReactCompositeComponent.js @@ -424,11 +424,14 @@ function validateLifeCycleOnReplaceState(instance) { compositeLifeCycleState === CompositeLifeCycle.MOUNTING, 'replaceState(...): Can only update a mounted or mounting component.' ); - invariant( - compositeLifeCycleState !== CompositeLifeCycle.RECEIVING_STATE && - compositeLifeCycleState !== CompositeLifeCycle.UNMOUNTING, - 'replaceState(...): Cannot update while unmounting component or during ' + - 'an existing state transition (such as within `render`).' + invariant(compositeLifeCycleState !== CompositeLifeCycle.RECEIVING_STATE, + 'replaceState(...): Cannot update during an existing state transition ' + + '(such as within `render`). This could potentially cause an infinite ' + + 'loop so it is forbidden.' + ); + invariant(compositeLifeCycleState !== CompositeLifeCycle.UNMOUNTING, + 'replaceState(...): Cannot update while unmounting component. This ' + + 'usually means you called setState() on an unmounted component.' ); }