From 6d2e55886ab8c92a08ce56d472fa921ea640b1ca Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Sun, 12 Jan 2025 14:45:41 -0500 Subject: [PATCH] Fix open app --- src/ONYXKEYS.ts | 4 ++++ src/libs/actions/App.ts | 20 +++++++++++++++++++- src/libs/actions/Delegate.ts | 1 + src/libs/actions/QueuedOnyxUpdates.ts | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 7b3eb78cf1e3..dce55b29b876 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -295,6 +295,9 @@ const ONYXKEYS = { /** Is report data loading? */ IS_LOADING_APP: 'isLoadingApp', + /** Is the app loaded? */ + HAS_LOADED_APP: 'hasLoadedApp', + /** Is the test tools modal open? */ IS_TEST_TOOLS_MODAL_OPEN: 'isTestToolsModalOpen', @@ -1011,6 +1014,7 @@ type OnyxValuesMapping = { [ONYXKEYS.IS_TEST_TOOLS_MODAL_OPEN]: boolean; [ONYXKEYS.APP_PROFILING_IN_PROGRESS]: boolean; [ONYXKEYS.IS_LOADING_APP]: boolean; + [ONYXKEYS.HAS_LOADED_APP]: boolean; [ONYXKEYS.WALLET_TRANSFER]: OnyxTypes.WalletTransfer; [ONYXKEYS.LAST_ACCESSED_WORKSPACE_POLICY_ID]: string; [ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT]: boolean; diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index 9c673288589e..581271d72c22 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -106,6 +106,14 @@ Onyx.connect({ }, }); +let hasLoadedApp: boolean | undefined; +Onyx.connect({ + key: ONYXKEYS.HAS_LOADED_APP, + callback: (value) => { + hasLoadedApp = value; + }, +}); + const KEYS_TO_PRESERVE: OnyxKey[] = [ ONYXKEYS.ACCOUNT, ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, @@ -239,7 +247,13 @@ function getOnyxDataForOpenOrReconnect(isOpenApp = false, isFullReconnect = fals value: true, }, ], - successData: [], + successData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.HAS_LOADED_APP, + value: true, + }, + ], finallyData: [ { onyxMethod: Onyx.METHOD.MERGE, @@ -291,6 +305,10 @@ function openApp() { * @param [updateIDFrom] the ID of the Onyx update that we want to start fetching from */ function reconnectApp(updateIDFrom: OnyxEntry = 0) { + if (!hasLoadedApp) { + openApp(); + return; + } console.debug(`[OnyxUpdates] App reconnecting with updateIDFrom: ${updateIDFrom}`); getPolicyParamsForOpenOrReconnect().then((policyParams) => { const params: ReconnectAppParams = policyParams; diff --git a/src/libs/actions/Delegate.ts b/src/libs/actions/Delegate.ts index dd4dfb24a908..7db91da05ce9 100644 --- a/src/libs/actions/Delegate.ts +++ b/src/libs/actions/Delegate.ts @@ -66,6 +66,7 @@ const KEYS_TO_PRESERVE_DELEGATE_ACCESS = [ ONYXKEYS.SESSION, ONYXKEYS.STASHED_SESSION, ONYXKEYS.IS_LOADING_APP, + ONYXKEYS.HAS_LOADED_APP, ONYXKEYS.STASHED_CREDENTIALS, // We need to preserve the sidebar loaded state since we never unrender the sidebar when connecting as a delegate diff --git a/src/libs/actions/QueuedOnyxUpdates.ts b/src/libs/actions/QueuedOnyxUpdates.ts index 46719f31b0d8..76709c0152f3 100644 --- a/src/libs/actions/QueuedOnyxUpdates.ts +++ b/src/libs/actions/QueuedOnyxUpdates.ts @@ -32,6 +32,7 @@ function flushQueue(): Promise { ONYXKEYS.NVP_PREFERRED_LOCALE, ONYXKEYS.SESSION, ONYXKEYS.IS_LOADING_APP, + ONYXKEYS.HAS_LOADED_APP, ONYXKEYS.CREDENTIALS, ONYXKEYS.IS_SIDEBAR_LOADED, ONYXKEYS.ACCOUNT,