@@ -802,7 +802,13 @@ function reportStorageQuota(error?: Error): Promise<void> {
802802 * - Non-retriable errors: logs an alert and resolves without retrying
803803 * - Other errors: retries the operation
804804 */
805- function retryOperation < TMethod extends RetriableOnyxOperation > ( error : Error , onyxMethod : TMethod , defaultParams : Parameters < TMethod > [ 0 ] , retryAttempt : number | undefined ) : Promise < void > {
805+ function retryOperation < TMethod extends RetriableOnyxOperation > (
806+ error : Error ,
807+ onyxMethod : TMethod ,
808+ defaultParams : Parameters < TMethod > [ 0 ] ,
809+ retryAttempt : number | undefined ,
810+ inFlightKeys ?: Set < OnyxKey > ,
811+ ) : Promise < void > {
806812 const currentRetryAttempt = retryAttempt ?? 0 ;
807813 const nextRetryAttempt = currentRetryAttempt + 1 ;
808814
@@ -847,10 +853,12 @@ function retryOperation<TMethod extends RetriableOnyxOperation>(error: Error, on
847853 Logger . logInfo ( `Out of storage. Evicting least recently accessed key (${ keyForRemoval } ) and retrying. Error: ${ error } ` ) ;
848854 reportStorageQuota ( error ) ;
849855
850- // skipNotify=true: retry's orchestrator skips keysChanged on retryAttempt > 0, so we
851- // must not let remove() fire keyChanged(undefined) — cache.set on retry restores the value.
856+ // Only suppress keyChanged(undefined) when the evicted key is part of the in-flight
857+ // write — then cache.set on retry will restore it. For unrelated keys, eviction is a
858+ // genuine loss and subscribers must see the removed state.
859+ const willBeRestored = inFlightKeys ?. has ( keyForRemoval ) ?? false ;
852860 // @ts -expect-error No overload matches this call.
853- return remove ( keyForRemoval , undefined , true ) . then ( ( ) => onyxMethod ( defaultParams , nextRetryAttempt ) ) ;
861+ return remove ( keyForRemoval , undefined , willBeRestored ) . then ( ( ) => onyxMethod ( defaultParams , nextRetryAttempt ) ) ;
854862}
855863
856864/**
@@ -1425,8 +1433,10 @@ function multiSetWithRetry(data: OnyxMultiSetInput, retryAttempt?: number): Prom
14251433 return ! OnyxKeys . isRamOnlyKey ( key ) ;
14261434 } ) ;
14271435
1436+ const inFlightKeys = new Set < OnyxKey > ( keyValuePairsToSet . map ( ( [ key ] ) => key ) ) ;
1437+
14281438 return Storage . multiSet ( keyValuePairsToStore )
1429- . catch ( ( error ) => OnyxUtils . retryOperation ( error , multiSetWithRetry , newData , retryAttempt ) )
1439+ . catch ( ( error ) => OnyxUtils . retryOperation ( error , multiSetWithRetry , newData , retryAttempt , inFlightKeys ) )
14301440 . then ( ( ) => {
14311441 OnyxUtils . sendActionToDevTools ( OnyxUtils . METHOD . MULTI_SET , undefined , newData ) ;
14321442 } ) ;
@@ -1502,8 +1512,10 @@ function setCollectionWithRetry<TKey extends CollectionKeyBase>({collectionKey,
15021512 return ;
15031513 }
15041514
1515+ const inFlightKeys = new Set < OnyxKey > ( keyValuePairs . map ( ( [ key ] ) => key ) ) ;
1516+
15051517 return Storage . multiSet ( keyValuePairs )
1506- . catch ( ( error ) => OnyxUtils . retryOperation ( error , setCollectionWithRetry , { collectionKey, collection} , retryAttempt ) )
1518+ . catch ( ( error ) => OnyxUtils . retryOperation ( error , setCollectionWithRetry , { collectionKey, collection} , retryAttempt , inFlightKeys ) )
15071519 . then ( ( ) => {
15081520 OnyxUtils . sendActionToDevTools ( OnyxUtils . METHOD . SET_COLLECTION , undefined , mutableCollection ) ;
15091521 } ) ;
@@ -1649,13 +1661,16 @@ function mergeCollectionWithPatches<TKey extends CollectionKeyBase>(
16491661 promises . push ( Storage . multiSet ( keyValuePairsForNewCollection ) ) ;
16501662 }
16511663
1664+ const inFlightKeys = new Set < OnyxKey > ( Object . keys ( finalMergedCollection ) ) ;
1665+
16521666 return Promise . all ( promises )
16531667 . catch ( ( error ) =>
16541668 retryOperation (
16551669 error ,
16561670 mergeCollectionWithPatches ,
16571671 { collectionKey, collection : resultCollection as OnyxMergeCollectionInput < TKey > , mergeReplaceNullPatches, isProcessingCollectionUpdate} ,
16581672 retryAttempt ,
1673+ inFlightKeys ,
16591674 ) ,
16601675 )
16611676 . then ( ( ) => {
@@ -1723,8 +1738,10 @@ function partialSetCollection<TKey extends CollectionKeyBase>({collectionKey, co
17231738 return ;
17241739 }
17251740
1741+ const inFlightKeys = new Set < OnyxKey > ( keyValuePairs . map ( ( [ key ] ) => key ) ) ;
1742+
17261743 return Storage . multiSet ( keyValuePairs )
1727- . catch ( ( error ) => retryOperation ( error , partialSetCollection , { collectionKey, collection} , retryAttempt ) )
1744+ . catch ( ( error ) => retryOperation ( error , partialSetCollection , { collectionKey, collection} , retryAttempt , inFlightKeys ) )
17281745 . then ( ( ) => {
17291746 sendActionToDevTools ( METHOD . SET_COLLECTION , undefined , mutableCollection ) ;
17301747 } ) ;
0 commit comments