@@ -75,9 +75,6 @@ type OnyxMethod = ValueOf<typeof METHOD>;
7575let mergeQueue : Record < OnyxKey , Array < OnyxValue < OnyxKey > > > = { } ;
7676let mergeQueuePromise : Record < OnyxKey , Promise < void > > = { } ;
7777
78- // Used to schedule subscriber update to the macro task queue
79- let nextMacrotaskPromise : Promise < void > | null = null ;
80-
8178// Holds a mapping of all the React components that want their state subscribed to a store key
8279let callbackToStateMapping : Record < string , CallbackToStateMapping < OnyxKey > > = { } ;
8380
@@ -803,23 +800,6 @@ function getCollectionDataAndSendAsObject<TKey extends OnyxKey>(matchingKeys: Co
803800 } ) ;
804801}
805802
806- /**
807- * Delays promise resolution until the next macrotask to prevent race condition if the key subscription is in progress.
808- *
809- * @param callback The keyChanged/keysChanged callback
810- * */
811- function prepareSubscriberUpdate ( callback : ( ) => void ) : Promise < void > {
812- if ( ! nextMacrotaskPromise ) {
813- nextMacrotaskPromise = new Promise < void > ( ( resolve ) => {
814- setTimeout ( ( ) => {
815- nextMacrotaskPromise = null ;
816- resolve ( ) ;
817- } , 0 ) ;
818- } ) ;
819- }
820- return Promise . all ( [ nextMacrotaskPromise , Promise . resolve ( ) . then ( callback ) ] ) . then ( ) ;
821- }
822-
823803/**
824804 * Schedules an update that will be appended to the macro task queue (so it doesn't update the subscribers immediately).
825805 *
@@ -831,21 +811,17 @@ function scheduleSubscriberUpdate<TKey extends OnyxKey>(
831811 value : OnyxValue < TKey > ,
832812 canUpdateSubscriber : ( subscriber ?: CallbackToStateMapping < OnyxKey > ) => boolean = ( ) => true ,
833813 isProcessingCollectionUpdate = false ,
834- ) : Promise < void > {
835- return prepareSubscriberUpdate ( ( ) => keyChanged ( key , value , canUpdateSubscriber , isProcessingCollectionUpdate ) ) ;
814+ ) : void {
815+ keyChanged ( key , value , canUpdateSubscriber , isProcessingCollectionUpdate ) ;
836816}
837817
838818/**
839819 * This method is similar to scheduleSubscriberUpdate but it is built for working specifically with collections
840820 * so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the
841821 * subscriber callbacks receive the data in a different format than they normally expect and it breaks code.
842822 */
843- function scheduleNotifyCollectionSubscribers < TKey extends OnyxKey > (
844- key : TKey ,
845- value : OnyxCollection < KeyValueMapping [ TKey ] > ,
846- previousValue ?: OnyxCollection < KeyValueMapping [ TKey ] > ,
847- ) : Promise < void > {
848- return prepareSubscriberUpdate ( ( ) => keysChanged ( key , value , previousValue ) ) ;
823+ function scheduleNotifyCollectionSubscribers < TKey extends OnyxKey > ( key : TKey , value : OnyxCollection < KeyValueMapping [ TKey ] > , previousValue ?: OnyxCollection < KeyValueMapping [ TKey ] > ) : void {
824+ keysChanged ( key , value , previousValue ) ;
849825}
850826
851827/**
@@ -919,7 +895,7 @@ function retryOperation<TMethod extends RetriableOnyxOperation>(error: Error, on
919895/**
920896 * Notifies subscribers and writes current value to cache
921897 */
922- function broadcastUpdate < TKey extends OnyxKey > ( key : TKey , value : OnyxValue < TKey > , hasChanged ?: boolean ) : Promise < void > {
898+ function broadcastUpdate < TKey extends OnyxKey > ( key : TKey , value : OnyxValue < TKey > , hasChanged ?: boolean ) : void {
923899 // Update subscribers if the cached value has changed, or when the subscriber specifically requires
924900 // all updates regardless of value changes (indicated by initWithStoredValues set to false).
925901 if ( hasChanged ) {
@@ -928,7 +904,7 @@ function broadcastUpdate<TKey extends OnyxKey>(key: TKey, value: OnyxValue<TKey>
928904 cache . addToAccessedKeys ( key ) ;
929905 }
930906
931- return scheduleSubscriberUpdate ( key , value , ( subscriber ) => hasChanged || subscriber ?. initWithStoredValues === false ) . then ( ( ) => undefined ) ;
907+ scheduleSubscriberUpdate ( key , value , ( subscriber ) => hasChanged || subscriber ?. initWithStoredValues === false ) ;
932908}
933909
934910function hasPendingMergeForKey ( key : OnyxKey ) : boolean {
@@ -1314,18 +1290,17 @@ function setWithRetry<TKey extends OnyxKey>({key, value, options}: SetParams<TKe
13141290 OnyxUtils . logKeyChanged ( OnyxUtils . METHOD . SET , key , value , hasChanged ) ;
13151291
13161292 // This approach prioritizes fast UI changes without waiting for data to be stored in device storage.
1317- const updatePromise = OnyxUtils . broadcastUpdate ( key , valueWithoutNestedNullValues , hasChanged ) ;
1293+ OnyxUtils . broadcastUpdate ( key , valueWithoutNestedNullValues , hasChanged ) ;
13181294
13191295 // If the value has not changed and this isn't a retry attempt, calling Storage.setItem() would be redundant and a waste of performance, so return early instead.
13201296 if ( ! hasChanged && ! retryAttempt ) {
1321- return updatePromise ;
1297+ return Promise . resolve ( ) ;
13221298 }
13231299
13241300 return Storage . setItem ( key , valueWithoutNestedNullValues )
13251301 . catch ( ( error ) => OnyxUtils . retryOperation ( error , setWithRetry , { key, value : valueWithoutNestedNullValues , options} , retryAttempt ) )
13261302 . then ( ( ) => {
13271303 OnyxUtils . sendActionToDevTools ( OnyxUtils . METHOD . SET , key , valueWithoutNestedNullValues ) ;
1328- return updatePromise ;
13291304 } ) ;
13301305}
13311306
0 commit comments