From cef441f413e2abcdfc0f69cd757b4ee7cf6a358d Mon Sep 17 00:00:00 2001 From: Kevin Brian Bader Date: Mon, 30 Dec 2024 14:31:43 -0800 Subject: [PATCH] Persist Use Staging Server option when clearing cache --- src/libs/actions/App.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index 931f9e226995..1bc9bde348fb 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -97,6 +97,14 @@ Onyx.connect({ }, }); +let preservedShouldUseStagingServer: boolean | undefined; +Onyx.connect({ + key: ONYXKEYS.USER, + callback: (value) => { + preservedShouldUseStagingServer = value?.shouldUseStagingServer; + }, +}); + const KEYS_TO_PRESERVE: OnyxKey[] = [ ONYXKEYS.ACCOUNT, ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, @@ -540,6 +548,7 @@ function setPreservedUserSession(session: OnyxTypes.Session) { function clearOnyxAndResetApp(shouldNavigateToHomepage?: boolean) { // The value of isUsingImportedState will be lost once Onyx is cleared, so we need to store it const isStateImported = isUsingImportedState; + const shouldUseStagingServer = preservedShouldUseStagingServer; const sequentialQueue = PersistedRequests.getAll(); Onyx.clear(KEYS_TO_PRESERVE).then(() => { // Network key is preserved, so when using imported state, we should stop forcing offline mode so that the app can re-fetch the network @@ -556,6 +565,10 @@ function clearOnyxAndResetApp(shouldNavigateToHomepage?: boolean) { Onyx.set(ONYXKEYS.PRESERVED_USER_SESSION, null); } + if (shouldUseStagingServer) { + Onyx.set(ONYXKEYS.USER, {shouldUseStagingServer}); + } + // Requests in a sequential queue should be called even if the Onyx state is reset, so we do not lose any pending data. // However, the OpenApp request must be called before any other request in a queue to ensure data consistency. // To do that, sequential queue is cleared together with other keys, and then it's restored once the OpenApp request is resolved.