@@ -64,6 +64,7 @@ export type UpdateQueue<State> = {
64
64
last : Update < State > | null ,
65
65
callbackList : Array < Update < State >> | null ,
66
66
hasForceUpdate : boolean ,
67
+ isInitialized : boolean ,
67
68
68
69
// Dev only
69
70
isProcessing ?: boolean ,
@@ -77,6 +78,7 @@ function createUpdateQueue<State>(baseState: State): UpdateQueue<State> {
77
78
last : null ,
78
79
callbackList : null ,
79
80
hasForceUpdate : false ,
81
+ isInitialized : false ,
80
82
} ;
81
83
if ( __DEV__ ) {
82
84
queue . isProcessing = false ;
@@ -204,6 +206,7 @@ function processUpdateQueue<State>(
204
206
expirationTime : currentQueue . expirationTime ,
205
207
first : currentQueue . first ,
206
208
last : currentQueue . last ,
209
+ isInitialized : currentQueue . isInitialized ,
207
210
// These fields are no longer valid because they were already committed.
208
211
// Reset them.
209
212
callbackList : null ,
@@ -225,9 +228,13 @@ function processUpdateQueue<State>(
225
228
// It depends on which fiber is the next current. Initialize with an empty
226
229
// base state, then set to the memoizedState when rendering. Not super
227
230
// 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
+ }
231
238
let dontMutatePrevState = true;
232
239
let update = queue.first;
233
240
let didSkip = false;
0 commit comments