From 76659c418f730c19fa4ca08320efd71d8de15b43 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Wed, 18 Oct 2017 15:39:58 -0700 Subject: [PATCH] Use sigil instead of comparing baseState to null --- src/renderers/shared/fiber/ReactFiberUpdateQueue.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/renderers/shared/fiber/ReactFiberUpdateQueue.js b/src/renderers/shared/fiber/ReactFiberUpdateQueue.js index a761975dd4..2a6cd6cf49 100644 --- a/src/renderers/shared/fiber/ReactFiberUpdateQueue.js +++ b/src/renderers/shared/fiber/ReactFiberUpdateQueue.js @@ -64,6 +64,7 @@ export type UpdateQueue = { last: Update | null, callbackList: Array> | null, hasForceUpdate: boolean, + isInitialized: boolean, // Dev only isProcessing?: boolean, @@ -77,6 +78,7 @@ function createUpdateQueue(baseState: State): UpdateQueue { last: null, callbackList: null, hasForceUpdate: false, + isInitialized: false, }; if (__DEV__) { queue.isProcessing = false; @@ -204,6 +206,7 @@ function processUpdateQueue( expirationTime: currentQueue.expirationTime, first: currentQueue.first, last: currentQueue.last, + isInitialized: currentQueue.isInitialized, // These fields are no longer valid because they were already committed. // Reset them. callbackList: null, @@ -225,9 +228,13 @@ function processUpdateQueue( // It depends on which fiber is the next current. Initialize with an empty // base state, then set to the memoizedState when rendering. Not super // happy with this approach. - let state = queue.baseState === null - ? workInProgress.memoizedState - : queue.baseState; + let state; + if (queue.isInitialized) { + state = queue.baseState; + } else { + state = queue.baseState = workInProgress.memoizedState; + queue.isInitialized = true; + } let dontMutatePrevState = true; let update = queue.first; let didSkip = false;