From adc1641fecbf95a2989265b345a43ab374ffcec1 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Tue, 21 Feb 2017 14:40:56 -0800 Subject: [PATCH] Should be able to setState inside cWRP before assigning to this.state ...without dropping the update. This won't work the other way around, if you assign to this.state before calling setState. we'll add a deprecation warning so people stop relying on this pattern. --- .../shared/stack/reconciler/ReactCompositeComponent.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js index f534cfd5c7..f1cc7086f4 100644 --- a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js +++ b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js @@ -850,6 +850,7 @@ var ReactCompositeComponent = { // _pendingStateQueue which will ensure that any state updates gets // immediately reconciled instead of waiting for the next batch. if (willReceive && inst.componentWillReceiveProps) { + const beforeState = inst.state; if (__DEV__) { measureLifeCyclePerf( () => inst.componentWillReceiveProps(nextProps, nextContext), @@ -859,6 +860,11 @@ var ReactCompositeComponent = { } else { inst.componentWillReceiveProps(nextProps, nextContext); } + const afterState = inst.state; + if (beforeState !== afterState) { + inst.state = beforeState; + inst.updater.enqueueReplaceState(inst, afterState); + } } // If updating happens to enqueue any new updates, we shouldn't execute new