File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -622,7 +622,7 @@ function clear(keysToPreserve: OnyxKey[] = []): Promise<void> {
622622
623623function updateSnapshots ( data : OnyxUpdate [ ] ) {
624624 const snapshotCollectionKey = OnyxUtils . getSnapshotKey ( ) ;
625- if ( ! snapshotCollectionKey ) return ;
625+ if ( ! snapshotCollectionKey ) return [ ] ;
626626
627627 const promises : Array < ( ) => Promise < void > > = [ ] ;
628628
@@ -676,7 +676,7 @@ function updateSnapshots(data: OnyxUpdate[]) {
676676 promises . push ( ( ) => merge ( snapshotKey , { data : updatedData } ) ) ;
677677 } ) ;
678678
679- return Promise . all ( promises . map ( ( p ) => p ( ) ) ) ;
679+ return promises ;
680680}
681681
682682/**
@@ -804,10 +804,12 @@ function update(data: OnyxUpdate[]): Promise<void> {
804804 }
805805 } ) ;
806806
807- return clearPromise
808- . then ( ( ) => Promise . all ( promises . map ( ( p ) => p ( ) ) ) )
809- . then ( ( ) => updateSnapshots ( data ) )
810- . then ( ( ) => undefined ) ;
807+ const snapshotPromises = updateSnapshots ( data ) ;
808+
809+ // We need to run the snapshot updates before the other updates so the snapshot data can be updated before the loading state in the snapshot
810+ const finalPromises = snapshotPromises . concat ( promises ) ;
811+
812+ return clearPromise . then ( ( ) => Promise . all ( finalPromises . map ( ( p ) => p ( ) ) ) ) . then ( ( ) => undefined ) ;
811813}
812814
813815/**
Original file line number Diff line number Diff line change @@ -1460,6 +1460,8 @@ describe('Onyx', () => {
14601460 callback,
14611461 } ) ;
14621462
1463+ await waitForPromisesToResolve ( ) ;
1464+
14631465 await Onyx . update ( [ { key : cat , value : finalValue , onyxMethod : Onyx . METHOD . MERGE } ] ) ;
14641466
14651467 expect ( callback ) . toBeCalledTimes ( 2 ) ;
You can’t perform that action at this time.
0 commit comments