From e66d7d99182082c46939c81e6084bb1031a48abf Mon Sep 17 00:00:00 2001 From: "marta.sudol" Date: Fri, 6 Jun 2025 08:59:51 +0200 Subject: [PATCH 1/7] fix: use staging server persistence --- src/libs/actions/SignInRedirect.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index d0cfc5352156..a238ae058a24 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -15,6 +15,14 @@ Onyx.connect({ }, }); +let shouldUseStagingServer: boolean | undefined; +Onyx.connect({ + key: ONYXKEYS.ACCOUNT, + callback: (account) => { + shouldUseStagingServer = account?.shouldUseStagingServer; + }, +}); + function clearStorageAndRedirect(errorMessage?: string): Promise { // Under certain conditions, there are key-values we'd like to keep in storage even when a user is logged out. // We pass these into the clear() method in order to avoid having to reset them on a delayed tick and getting @@ -31,8 +39,17 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { keysToPreserve.push(ONYXKEYS.NETWORK); } + // Preserve the staging server setting across logout + const stagingServerSetting = shouldUseStagingServer; + return Onyx.clear(keysToPreserve).then(() => { clearAllPolicies(); + + // Restore the staging server setting if it was set + if (stagingServerSetting !== undefined) { + Onyx.merge(ONYXKEYS.ACCOUNT, {shouldUseStagingServer: stagingServerSetting}); + } + if (!errorMessage) { return; } From d356c7c99801bd6ac72c1beabb6c40595b124f82 Mon Sep 17 00:00:00 2001 From: "marta.sudol" Date: Fri, 6 Jun 2025 14:53:27 +0200 Subject: [PATCH 2/7] prettier --- src/libs/actions/SignInRedirect.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index a238ae058a24..d239d24cdfe5 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -44,12 +44,12 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { return Onyx.clear(keysToPreserve).then(() => { clearAllPolicies(); - + // Restore the staging server setting if it was set if (stagingServerSetting !== undefined) { Onyx.merge(ONYXKEYS.ACCOUNT, {shouldUseStagingServer: stagingServerSetting}); } - + if (!errorMessage) { return; } From 8ca51544f7dfc3dca88299f08c6056241165e4e2 Mon Sep 17 00:00:00 2001 From: "marta.sudol" Date: Wed, 11 Jun 2025 09:44:07 +0200 Subject: [PATCH 3/7] fix for all other flags --- src/libs/actions/SignInRedirect.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index d239d24cdfe5..66ba69a81920 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -16,13 +16,16 @@ Onyx.connect({ }); let shouldUseStagingServer: boolean | undefined; +let isDebugModeEnabled: boolean | undefined; Onyx.connect({ key: ONYXKEYS.ACCOUNT, callback: (account) => { shouldUseStagingServer = account?.shouldUseStagingServer; + isDebugModeEnabled = account?.isDebugModeEnabled; }, }); + function clearStorageAndRedirect(errorMessage?: string): Promise { // Under certain conditions, there are key-values we'd like to keep in storage even when a user is logged out. // We pass these into the clear() method in order to avoid having to reset them on a delayed tick and getting @@ -39,15 +42,28 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { keysToPreserve.push(ONYXKEYS.NETWORK); } - // Preserve the staging server setting across logout + // Preserve troubleshooting flags + keysToPreserve.push(ONYXKEYS.APP_PROFILING_IN_PROGRESS); + keysToPreserve.push(ONYXKEYS.SHOULD_STORE_LOGS); + keysToPreserve.push(ONYXKEYS.SHOULD_MASK_ONYX_STATE); + + // Preserve the staging server setting and debug mode across logout const stagingServerSetting = shouldUseStagingServer; + const debugModeSetting = isDebugModeEnabled; return Onyx.clear(keysToPreserve).then(() => { clearAllPolicies(); - // Restore the staging server setting if it was set + // Restore the staging server and debug mode settings if they were set + const accountSettings: Record = {}; if (stagingServerSetting !== undefined) { - Onyx.merge(ONYXKEYS.ACCOUNT, {shouldUseStagingServer: stagingServerSetting}); + accountSettings.shouldUseStagingServer = stagingServerSetting; + } + if (debugModeSetting !== undefined) { + accountSettings.isDebugModeEnabled = debugModeSetting; + } + if (Object.keys(accountSettings).length > 0) { + Onyx.merge(ONYXKEYS.ACCOUNT, accountSettings); } if (!errorMessage) { From 547808b1cb92cd80469e3ef1681d3cef971c8a56 Mon Sep 17 00:00:00 2001 From: "marta.sudol" Date: Wed, 11 Jun 2025 09:49:18 +0200 Subject: [PATCH 4/7] prettier --- src/libs/actions/SignInRedirect.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index 66ba69a81920..94e9d40d81be 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -25,7 +25,6 @@ Onyx.connect({ }, }); - function clearStorageAndRedirect(errorMessage?: string): Promise { // Under certain conditions, there are key-values we'd like to keep in storage even when a user is logged out. // We pass these into the clear() method in order to avoid having to reset them on a delayed tick and getting From b2fb200dbb206c984594ec720b9293479111f71d Mon Sep 17 00:00:00 2001 From: "marta.sudol" Date: Mon, 23 Jun 2025 12:31:10 +0200 Subject: [PATCH 5/7] fix: flickering on auth state changes --- src/pages/signin/SignInPage.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pages/signin/SignInPage.tsx b/src/pages/signin/SignInPage.tsx index 1cd6b2c04ef6..7ee0adef97ae 100644 --- a/src/pages/signin/SignInPage.tsx +++ b/src/pages/signin/SignInPage.tsx @@ -106,7 +106,8 @@ function getRenderOptions({ // SAML required users may reload the login page after having already entered their login details, in which // case we want to clear their sign in data so they don't end up in an infinite loop redirecting back to their // SSO provider's login page - if (hasLogin && isSAMLRequired && !shouldInitiateSAMLLogin && !hasInitiatedSAMLLogin && !account.isLoading) { + // Don't clear if we don't have account data - this prevents clearing during app resets when state is inconsistent + if (hasAccount && hasLogin && isSAMLRequired && !shouldInitiateSAMLLogin && !hasInitiatedSAMLLogin && !account.isLoading) { clearSignInData(); } @@ -178,6 +179,7 @@ function SignInPage({shouldEnableMaxHeight = true}: SignInPageInnerProps, ref: F * if we need to clear their sign in details so they can enter a login */ const [hasInitiatedSAMLLogin, setHasInitiatedSAMLLogin] = useState(false); + const isClientTheLeader = !!activeClients && isClientTheLeaderActiveClientManager(); // We need to show "Another login page is opened" message if the page isn't active and visible // eslint-disable-next-line rulesdir/no-negated-variables @@ -224,7 +226,7 @@ function SignInPage({shouldEnableMaxHeight = true}: SignInPageInnerProps, ref: F hasInitiatedSAMLLogin, shouldShowAnotherLoginPageOpenedMessage, credentials, - isAccountValidated, + isAccountValidated }); if (shouldInitiateSAMLLogin) { From d7d6781be9ac55778fa53eb59ac4e1df9a093fa1 Mon Sep 17 00:00:00 2001 From: "marta.sudol" Date: Mon, 23 Jun 2025 12:46:07 +0200 Subject: [PATCH 6/7] prettier --- src/pages/signin/SignInPage.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/signin/SignInPage.tsx b/src/pages/signin/SignInPage.tsx index 7ee0adef97ae..11db1b00c5f4 100644 --- a/src/pages/signin/SignInPage.tsx +++ b/src/pages/signin/SignInPage.tsx @@ -179,7 +179,6 @@ function SignInPage({shouldEnableMaxHeight = true}: SignInPageInnerProps, ref: F * if we need to clear their sign in details so they can enter a login */ const [hasInitiatedSAMLLogin, setHasInitiatedSAMLLogin] = useState(false); - const isClientTheLeader = !!activeClients && isClientTheLeaderActiveClientManager(); // We need to show "Another login page is opened" message if the page isn't active and visible // eslint-disable-next-line rulesdir/no-negated-variables @@ -226,7 +225,7 @@ function SignInPage({shouldEnableMaxHeight = true}: SignInPageInnerProps, ref: F hasInitiatedSAMLLogin, shouldShowAnotherLoginPageOpenedMessage, credentials, - isAccountValidated + isAccountValidated, }); if (shouldInitiateSAMLLogin) { From 83a9a32fb14bd07012b895d1c3e0fb7476fb97d8 Mon Sep 17 00:00:00 2001 From: "marta.sudol" Date: Mon, 23 Jun 2025 13:25:13 +0200 Subject: [PATCH 7/7] prettier --- src/libs/actions/SignInRedirect.ts | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index d36247922f9a..3e28fdcfb2f2 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -17,16 +17,6 @@ Onyx.connect({ }, }); -let shouldUseStagingServer: boolean | undefined; -let isDebugModeEnabled: boolean | undefined; -Onyx.connect({ - key: ONYXKEYS.ACCOUNT, - callback: (account) => { - shouldUseStagingServer = account?.shouldUseStagingServer; - isDebugModeEnabled = account?.isDebugModeEnabled; - }, -}); - function clearStorageAndRedirect(errorMessage?: string): Promise { // Under certain conditions, there are key-values we'd like to keep in storage even when a user is logged out. // We pass these into the clear() method in order to avoid having to reset them on a delayed tick and getting @@ -49,9 +39,8 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { keysToPreserve.push(ONYXKEYS.SHOULD_STORE_LOGS); keysToPreserve.push(ONYXKEYS.SHOULD_MASK_ONYX_STATE); - // Preserve the staging server setting and debug mode across logout - const stagingServerSetting = shouldUseStagingServer; - const debugModeSetting = isDebugModeEnabled; + // Preserve account settings (staging server, debug mode, etc.) across logout + keysToPreserve.push(ONYXKEYS.ACCOUNT); return Onyx.clear(keysToPreserve).then(() => { if (CONFIG.IS_HYBRID_APP) { @@ -59,18 +48,6 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { } clearAllPolicies(); - // Restore the staging server and debug mode settings if they were set - const accountSettings: Record = {}; - if (stagingServerSetting !== undefined) { - accountSettings.shouldUseStagingServer = stagingServerSetting; - } - if (debugModeSetting !== undefined) { - accountSettings.isDebugModeEnabled = debugModeSetting; - } - if (Object.keys(accountSettings).length > 0) { - Onyx.merge(ONYXKEYS.ACCOUNT, accountSettings); - } - if (!errorMessage) { return; }