Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist Use Staging Server option when clearing cache #54673

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/libs/actions/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
Loading