Skip to content

Commit 76659c4

Browse files
committed
Use sigil instead of comparing baseState to null
1 parent d964728 commit 76659c4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/renderers/shared/fiber/ReactFiberUpdateQueue.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export type UpdateQueue<State> = {
6464
last: Update<State> | null,
6565
callbackList: Array<Update<State>> | null,
6666
hasForceUpdate: boolean,
67+
isInitialized: boolean,
6768

6869
// Dev only
6970
isProcessing?: boolean,
@@ -77,6 +78,7 @@ function createUpdateQueue<State>(baseState: State): UpdateQueue<State> {
7778
last: null,
7879
callbackList: null,
7980
hasForceUpdate: false,
81+
isInitialized: false,
8082
};
8183
if (__DEV__) {
8284
queue.isProcessing = false;
@@ -204,6 +206,7 @@ function processUpdateQueue<State>(
204206
expirationTime: currentQueue.expirationTime,
205207
first: currentQueue.first,
206208
last: currentQueue.last,
209+
isInitialized: currentQueue.isInitialized,
207210
// These fields are no longer valid because they were already committed.
208211
// Reset them.
209212
callbackList: null,
@@ -225,9 +228,13 @@ function processUpdateQueue<State>(
225228
// It depends on which fiber is the next current. Initialize with an empty
226229
// base state, then set to the memoizedState when rendering. Not super
227230
// happy with this approach.
228-
let state = queue.baseState === null
229-
? workInProgress.memoizedState
230-
: queue.baseState;
231+
let state;
232+
if (queue.isInitialized) {
233+
state = queue.baseState;
234+
} else {
235+
state = queue.baseState = workInProgress.memoizedState;
236+
queue.isInitialized = true;
237+
}
231238
let dontMutatePrevState = true;
232239
let update = queue.first;
233240
let didSkip = false;

0 commit comments

Comments
 (0)