File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -238,6 +238,11 @@ function multiSet(data: OnyxMultiSetInput): Promise<void> {
238238
239239 const updatePromises = keyValuePairsToSet . map ( ( [ key , value ] ) => {
240240 const prevValue = cache . get ( key , false ) ;
241+ // When we use multiSet to set a key we want to clear the current delta changes from Onyx.merge that were queued
242+ // before the value was set. If Onyx.merge is currently reading the old value from storage, it will then not apply the changes.
243+ if ( OnyxUtils . hasPendingMergeForKey ( key ) ) {
244+ delete OnyxUtils . getMergeQueue ( ) [ key ] ;
245+ }
241246
242247 // Update cache and optimistically inform subscribers on the next tick
243248 cache . set ( key , value ) ;
Original file line number Diff line number Diff line change @@ -2029,5 +2029,25 @@ describe('Onyx', () => {
20292029 [ `${ ONYX_KEYS . COLLECTION . TEST_KEY } entry2` ] : { id : 'entry2_id' , name : 'entry2_name' } ,
20302030 } ) ;
20312031 } ) ;
2032+ it ( 'should clear pending merge for a key during multiSet()' , async ( ) => {
2033+ const testKey = `${ ONYX_KEYS . COLLECTION . TEST_KEY } entry1` ;
2034+
2035+ // Mock the merge queue with the correct type
2036+ const mockMergeQueue : Record < string , unknown [ ] > = {
2037+ [ testKey ] : [ { some : 'mergeData' } ] ,
2038+ } ;
2039+
2040+ // Mock the utility functions
2041+ jest . spyOn ( OnyxUtils , 'hasPendingMergeForKey' ) . mockImplementation ( ( key ) => key === testKey ) ;
2042+ jest . spyOn ( OnyxUtils , 'getMergeQueue' ) . mockImplementation ( ( ) => mockMergeQueue ) ;
2043+
2044+ await Onyx . multiSet ( {
2045+ [ testKey ] : { id : 'entry1_id' , name : 'entry1_name' } ,
2046+ } ) ;
2047+
2048+ expect ( mockMergeQueue [ testKey ] ) . toBeUndefined ( ) ;
2049+
2050+ jest . restoreAllMocks ( ) ;
2051+ } ) ;
20322052 } ) ;
20332053} ) ;
You can’t perform that action at this time.
0 commit comments