From 8707755676ddeb8d775ea5c2af0ce28b319733ce Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Wed, 18 Oct 2017 14:32:31 -0700 Subject: [PATCH] Render-phase setState bugfix (#11272) Fixes a bug surfaced by www unit test. I'm not yet sure the best way to test this; in the interest of landing this fix quickly, I'll save the test for a follow-up. --- src/renderers/shared/fiber/ReactFiberUpdateQueue.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/renderers/shared/fiber/ReactFiberUpdateQueue.js b/src/renderers/shared/fiber/ReactFiberUpdateQueue.js index 5da8671536..4fe8c9d8b2 100644 --- a/src/renderers/shared/fiber/ReactFiberUpdateQueue.js +++ b/src/renderers/shared/fiber/ReactFiberUpdateQueue.js @@ -198,7 +198,12 @@ function processUpdateQueue( // We need to create a work-in-progress queue, by cloning the current queue. const currentQueue = queue; queue = workInProgress.updateQueue = { - baseState: currentQueue.baseState, + // If we hit this clone path, the work-in-progress update queue is + // conceptually empty. Which means its base state is the same as its + // memoized state. This usually the same as the current queue's base + // state, but could be different if setState was called during a child's + // render phase. + baseState: workInProgress.memoizedState, expirationTime: currentQueue.expirationTime, first: currentQueue.first, last: currentQueue.last,