@@ -131,6 +131,12 @@ function disconnect(connection: Connection): void {
131131 * @param value value to store
132132 */
133133function set < TKey extends OnyxKey > ( key : TKey , value : OnyxSetInput < TKey > ) : Promise < void > {
134+ // When we use Onyx.set to set a key we want to clear the current delta changes from Onyx.merge that were queued
135+ // before the value was set. If Onyx.merge is currently reading the old value from storage, it will then not apply the changes.
136+ if ( OnyxUtils . hasPendingMergeForKey ( key ) ) {
137+ delete OnyxUtils . getMergeQueue ( ) [ key ] ;
138+ }
139+
134140 const skippableCollectionMemberIDs = OnyxUtils . getSkippableCollectionMemberIDs ( ) ;
135141 if ( skippableCollectionMemberIDs . size ) {
136142 try {
@@ -143,12 +149,6 @@ function set<TKey extends OnyxKey>(key: TKey, value: OnyxSetInput<TKey>): Promis
143149 }
144150 }
145151
146- // When we use Onyx.set to set a key we want to clear the current delta changes from Onyx.merge that were queued
147- // before the value was set. If Onyx.merge is currently reading the old value from storage, it will then not apply the changes.
148- if ( OnyxUtils . hasPendingMergeForKey ( key ) ) {
149- delete OnyxUtils . getMergeQueue ( ) [ key ] ;
150- }
151-
152152 // Onyx.set will ignore `undefined` values as inputs, therefore we can return early.
153153 if ( value === undefined ) {
154154 return Promise . resolve ( ) ;
@@ -218,10 +218,8 @@ function multiSet(data: OnyxMultiSetInput): Promise<void> {
218218 newData = Object . keys ( newData ) . reduce ( ( result : OnyxMultiSetInput , key ) => {
219219 try {
220220 const [ , collectionMemberID ] = OnyxUtils . splitCollectionMemberKey ( key ) ;
221- if ( ! skippableCollectionMemberIDs . has ( collectionMemberID ) ) {
222- // eslint-disable-next-line no-param-reassign
223- result [ key ] = newData [ key ] ;
224- }
221+ // eslint-disable-next-line no-param-reassign
222+ result [ key ] = ! skippableCollectionMemberIDs . has ( collectionMemberID ) ? newData [ key ] : null ;
225223 } catch {
226224 // Key is not a collection one or something went wrong during split, so we assign the data to result anyway.
227225 // eslint-disable-next-line no-param-reassign
@@ -273,7 +271,8 @@ function merge<TKey extends OnyxKey>(key: TKey, changes: OnyxMergeInput<TKey>):
273271 try {
274272 const [ , collectionMemberID ] = OnyxUtils . splitCollectionMemberKey ( key ) ;
275273 if ( skippableCollectionMemberIDs . has ( collectionMemberID ) ) {
276- return Promise . resolve ( ) ;
274+ // eslint-disable-next-line no-param-reassign
275+ changes = undefined ;
277276 }
278277 } catch ( e ) {
279278 // Key is not a collection one or something went wrong during split, so we proceed with the function's logic.
@@ -407,10 +406,8 @@ function mergeCollection<TKey extends CollectionKeyBase, TMap>(collectionKey: TK
407406 resultCollection = Object . keys ( resultCollection ) . reduce ( ( result : OnyxInputKeyValueMapping , key ) => {
408407 try {
409408 const [ , collectionMemberID ] = OnyxUtils . splitCollectionMemberKey ( key , collectionKey ) ;
410- if ( ! skippableCollectionMemberIDs . has ( collectionMemberID ) ) {
411- // eslint-disable-next-line no-param-reassign
412- result [ key ] = resultCollection [ key ] ;
413- }
409+ // eslint-disable-next-line no-param-reassign
410+ result [ key ] = ! skippableCollectionMemberIDs . has ( collectionMemberID ) ? resultCollection [ key ] : null ;
414411 } catch {
415412 // Something went wrong during split, so we assign the data to result anyway.
416413 // eslint-disable-next-line no-param-reassign
@@ -825,10 +822,8 @@ function setCollection<TKey extends CollectionKeyBase, TMap>(collectionKey: TKey
825822 resultCollection = Object . keys ( resultCollection ) . reduce ( ( result : OnyxInputKeyValueMapping , key ) => {
826823 try {
827824 const [ , collectionMemberID ] = OnyxUtils . splitCollectionMemberKey ( key , collectionKey ) ;
828- if ( ! skippableCollectionMemberIDs . has ( collectionMemberID ) ) {
829- // eslint-disable-next-line no-param-reassign
830- result [ key ] = resultCollection [ key ] ;
831- }
825+ // eslint-disable-next-line no-param-reassign
826+ result [ key ] = ! skippableCollectionMemberIDs . has ( collectionMemberID ) ? resultCollection [ key ] : null ;
832827 } catch {
833828 // Something went wrong during split, so we assign the data to result anyway.
834829 // eslint-disable-next-line no-param-reassign
0 commit comments