@@ -504,7 +504,7 @@ async function handleConflictActions<TKey extends OnyxKey>(conflictAction: Confl
504504 }
505505}
506506
507- function push < TKey extends OnyxKey > ( newRequest : OnyxRequest < TKey > ) : Promise < void > {
507+ async function push < TKey extends OnyxKey > ( newRequest : OnyxRequest < TKey > ) : Promise < void > {
508508 const currentRequests = getAllPersistedRequests ( ) ;
509509 Log . info ( '[SequentialQueue] push() called' , false , {
510510 command : newRequest . command ,
@@ -514,19 +514,10 @@ function push<TKey extends OnyxKey>(newRequest: OnyxRequest<TKey>): Promise<void
514514 isSequentialQueueRunning,
515515 } ) ;
516516
517- // Save the request to the persisted queue. The in-memory update inside save()
518- // happens synchronously, so flush() below will see the new request immediately.
519- // The returned promise resolves when disk persistence completes.
520517 let persistencePromise : Promise < void > ;
521518
522519 if ( newRequest . checkAndFixConflictingRequest ) {
523- const requests = currentRequests ;
524- Log . info ( '[SequentialQueue] Checking for conflicts' , false , {
525- command : newRequest . command ,
526- existingRequestsCount : requests . length ,
527- } ) ;
528-
529- const { conflictAction} = newRequest . checkAndFixConflictingRequest ( requests as Array < OnyxRequest < TKey > > ) ;
520+ const { conflictAction} = newRequest . checkAndFixConflictingRequest ( currentRequests as Array < OnyxRequest < TKey > > ) ;
530521 Log . info ( '[SequentialQueue] Conflict action determined' , false , {
531522 command : newRequest . command ,
532523 conflictType : conflictAction . type ,
@@ -537,41 +528,30 @@ function push<TKey extends OnyxKey>(newRequest: OnyxRequest<TKey>): Promise<void
537528 delete newRequest . checkAndFixConflictingRequest ;
538529 persistencePromise = handleConflictActions ( conflictAction , newRequest ) ;
539530 } else {
540- Log . info ( '[SequentialQueue] No conflict action. Adding request to Persisted Requests' , false , {
541- command : newRequest . command ,
542- } ) ;
543- // Add request to Persisted Requests so that it can be retried if it fails
544531 persistencePromise = savePersistedRequest ( newRequest ) ;
545532 }
546533
547- // If we are offline we don't need to trigger the queue to empty as it will happen when we come back online
534+ // Block until the Onyx disk commit lands so a process kill between here and the XHR
535+ // still leaves the request recoverable from storage on next launch.
536+ await persistencePromise ;
537+
548538 if ( isOfflineNetwork ( ) ) {
549539 Log . info ( '[SequentialQueue] Request persisted but not flushing — we are offline' , false , {
550540 command : newRequest . command ,
551541 queueLength : getAllPersistedRequests ( ) . length ,
552542 } ) ;
553- return persistencePromise ;
543+ return ;
554544 }
555545
556- // If the queue is running this request will run once it has finished processing the current batch
557546 if ( isSequentialQueueRunning ) {
558547 Log . info ( '[SequentialQueue] Queue is running. Will flush when the current request is finished.' , false , {
559548 command : newRequest . command ,
560549 } ) ;
561- isReadyPromise . then ( ( ) => {
562- Log . info ( '[SequentialQueue] isReadyPromise resolved, flushing queue' , false , {
563- command : newRequest . command ,
564- } ) ;
565- flush ( true ) ;
566- } ) ;
567- return persistencePromise ;
550+ isReadyPromise . then ( ( ) => flush ( true ) ) ;
551+ return ;
568552 }
569553
570- Log . info ( '[SequentialQueue] Queue is not running. Flushing the queue.' , false , {
571- command : newRequest . command ,
572- } ) ;
573554 flush ( true ) ;
574- return persistencePromise ;
575555}
576556
577557function getCurrentRequest ( ) : Promise < void > {
0 commit comments