Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ const ONYXKEYS = {
/** Indicates whether an forced upgrade is required */
UPDATE_REQUIRED: 'updateRequired',

/** Indicates whether an forced reset is required. Used in emergency situations where we must completely erase the Onyx data in the client because it is in a bad state. This will clear Oynx data without signing the user out. */
RESET_REQUIRED: 'resetRequired',

/** Stores the logs of the app for debugging purposes */
LOGS: 'logs',

Expand Down Expand Up @@ -638,6 +641,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.LAST_VISITED_PATH]: string | undefined;
[ONYXKEYS.RECENTLY_USED_REPORT_FIELDS]: OnyxTypes.RecentlyUsedReportFields;
[ONYXKEYS.UPDATE_REQUIRED]: boolean;
[ONYXKEYS.RESET_REQUIRED]: boolean;
[ONYXKEYS.PLAID_CURRENT_EVENT]: string;
[ONYXKEYS.LOGS]: OnyxTypes.CapturedLogs;
[ONYXKEYS.SHOULD_STORE_LOGS]: boolean;
Expand Down
34 changes: 34 additions & 0 deletions src/libs/actions/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as SessionUtils from '@libs/SessionUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {OnyxKey} from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
Expand Down Expand Up @@ -77,6 +78,38 @@ Onyx.connect({
},
});

const KEYS_TO_PRESERVE: OnyxKey[] = [
ONYXKEYS.ACCOUNT,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcaaron Was there any specific reason not to include ONYXKEYS.USER here? We're considering adding it in #49087, but wanted to check first if there are any good arguments against doing so.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't think of a reason! Thanks for asking! The array of keys also predates this PR so we could also ask the author of the original PR that introduced this change.

ONYXKEYS.IS_CHECKING_PUBLIC_ROOM,
ONYXKEYS.IS_LOADING_APP,
ONYXKEYS.IS_SIDEBAR_LOADED,
ONYXKEYS.MODAL,
ONYXKEYS.NETWORK,
ONYXKEYS.SESSION,
ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT,
ONYXKEYS.NVP_TRY_FOCUS_MODE,
ONYXKEYS.PREFERRED_THEME,
ONYXKEYS.NVP_PREFERRED_LOCALE,
ONYXKEYS.CREDENTIALS,
];

Onyx.connect({
key: ONYXKEYS.RESET_REQUIRED,
callback: (isResetRequired) => {
if (!isResetRequired) {
return;
}

Onyx.clear(KEYS_TO_PRESERVE).then(() => {
// Set this to false to reset the flag for this client
Onyx.set(ONYXKEYS.RESET_REQUIRED, false);

// eslint-disable-next-line @typescript-eslint/no-use-before-define
openApp();
});
},
});

let resolveIsReadyPromise: () => void;
const isReadyToOpenApp = new Promise<void>((resolve) => {
resolveIsReadyPromise = resolve;
Expand Down Expand Up @@ -527,4 +560,5 @@ export {
savePolicyDraftByNewWorkspace,
createWorkspaceWithPolicyDraftAndNavigateToIt,
updateLastVisitedPath,
KEYS_TO_PRESERVE,
};
18 changes: 1 addition & 17 deletions src/pages/settings/AboutPage/TroubleshootPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,9 @@ import * as App from '@userActions/App';
import * as Report from '@userActions/Report';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type {OnyxKey} from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';

const keysToPreserve: OnyxKey[] = [
ONYXKEYS.ACCOUNT,
ONYXKEYS.IS_CHECKING_PUBLIC_ROOM,
ONYXKEYS.IS_LOADING_APP,
ONYXKEYS.IS_SIDEBAR_LOADED,
ONYXKEYS.MODAL,
ONYXKEYS.NETWORK,
ONYXKEYS.SESSION,
ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT,
ONYXKEYS.NVP_TRY_FOCUS_MODE,
ONYXKEYS.PREFERRED_THEME,
ONYXKEYS.NVP_PREFERRED_LOCALE,
ONYXKEYS.CREDENTIALS,
];

type BaseMenuItem = {
translationKey: TranslationPaths;
icon: React.FC<SvgProps>;
Expand Down Expand Up @@ -128,7 +112,7 @@ function TroubleshootPage({shouldStoreLogs}: TroubleshootPageProps) {
isVisible={isConfirmationModalVisible}
onConfirm={() => {
setIsConfirmationModalVisible(false);
Onyx.clear(keysToPreserve).then(() => {
Onyx.clear(App.KEYS_TO_PRESERVE).then(() => {
App.openApp();
});
}}
Expand Down