@@ -4,6 +4,7 @@ import type {OnyxEntry, OnyxKey, OnyxUpdate} from 'react-native-onyx';
44import * as API from '@libs/API' ;
55import type { AddDelegateParams as APIAddDelegateParams , RemoveDelegateParams as APIRemoveDelegateParams , UpdateDelegateRoleParams as APIUpdateDelegateRoleParams } from '@libs/API/parameters' ;
66import { READ_COMMANDS , SIDE_EFFECT_REQUEST_COMMANDS , WRITE_COMMANDS } from '@libs/API/types' ;
7+ import DateUtils from '@libs/DateUtils' ;
78import * as ErrorUtils from '@libs/ErrorUtils' ;
89import Log from '@libs/Log' ;
910import { clearPreservedSearchNavigatorStates } from '@libs/Navigation/AppNavigator/createSplitNavigator/usePreserveNavigatorState' ;
@@ -42,14 +43,25 @@ const KEYS_TO_PRESERVE_DELEGATE_ACCESS = [
4243] ;
4344
4445/**
45- * Atomically reset Onyx for a delegate-access transition while keeping IS_LOADING_APP=true
46- * so consumers never observe the post-clear state with HAS_LOADED_APP=true and
47- * IS_LOADING_APP=undefined. That combination falsely looks like a stuck app and triggers
48- * DelegateAccessHandler's recovery effect, producing a duplicate openApp queued behind the
49- * explicit openApp the caller is about to make.
46+ * Atomically reset Onyx for a delegate-access transition while seeding two values that
47+ * subscribers would otherwise misinterpret on the post-clear state and double up calls
48+ * the caller is about to make explicitly:
49+ *
50+ * - IS_LOADING_APP=true: without it, consumers observe HAS_LOADED_APP=true and
51+ * IS_LOADING_APP=undefined together, which looks like a stuck app and triggers
52+ * DelegateAccessHandler's recovery effect, queueing a duplicate openApp.
53+ * - LAST_FULL_RECONNECT_TIME=now: subscribeToFullReconnect compares this against the
54+ * server-supplied NVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFORE that lands in OpenApp's
55+ * response.onyxData. Because applyHTTPSOnyxUpdates applies response.onyxData before
56+ * successData, the timestamp would still be empty when the comparison runs, falsely
57+ * triggering a duplicate ReconnectApp. Seeding to `now` short-circuits the subscriber
58+ * until OpenApp's successData refreshes it.
5059 */
5160function clearOnyxForDelegateTransition ( ) : Promise < void > {
52- return Onyx . merge ( ONYXKEYS . IS_LOADING_APP , true ) . then ( ( ) => Onyx . clear ( [ ...KEYS_TO_PRESERVE_DELEGATE_ACCESS , ONYXKEYS . IS_LOADING_APP ] ) ) ;
61+ return Onyx . multiSet ( {
62+ [ ONYXKEYS . IS_LOADING_APP ] : true ,
63+ [ ONYXKEYS . LAST_FULL_RECONNECT_TIME ] : DateUtils . getDBTime ( ) ,
64+ } ) . then ( ( ) => Onyx . clear ( [ ...KEYS_TO_PRESERVE_DELEGATE_ACCESS , ONYXKEYS . IS_LOADING_APP , ONYXKEYS . LAST_FULL_RECONNECT_TIME ] ) ) ;
5365}
5466
5567type WithDelegatedAccess = {
0 commit comments