From 62e9819f4467a0531e59c267955298df2bd49e17 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 17 Sep 2024 16:12:14 +0200 Subject: [PATCH 1/6] add consts --- src/CONST.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CONST.ts b/src/CONST.ts index c00b33be1c31..3d8ca3dc30b4 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -5424,6 +5424,7 @@ const CONST = { INITIAL_URL: 'INITIAL_URL', ACTIVE_WORKSPACE_ID: 'ACTIVE_WORKSPACE_ID', RETRY_LAZY_REFRESHED: 'RETRY_LAZY_REFRESHED', + LAST_REFRESH_TIMESTAMP: 'LAST_REFRESH_TIMESTAMP', }, RESERVATION_TYPE: { @@ -5753,6 +5754,9 @@ const CONST = { CATEGORIES_ARTICLE_LINK: 'https://help.expensify.com/articles/expensify-classic/workspaces/Create-categories#import-custom-categories', }, + + // The timeout duration (1 minute) (in milliseconds) before the window reloads due to an error. + ERROR_WINDOW_RELOAD_TIMEOUT: 60000, } as const; type Country = keyof typeof CONST.ALL_COUNTRIES; From de80004ecc5ff296683065809bb27ecfa632b640 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 17 Sep 2024 16:12:47 +0200 Subject: [PATCH 2/6] integrate refresh or reload in GenericErrorPage --- src/pages/ErrorPage/GenericErrorPage.tsx | 28 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/pages/ErrorPage/GenericErrorPage.tsx b/src/pages/ErrorPage/GenericErrorPage.tsx index 9f4186bc354f..4d7c2f649208 100644 --- a/src/pages/ErrorPage/GenericErrorPage.tsx +++ b/src/pages/ErrorPage/GenericErrorPage.tsx @@ -1,3 +1,4 @@ +import differenceInMilliseconds from 'date-fns/differenceInMilliseconds'; import React from 'react'; import {useErrorBoundary} from 'react-error-boundary'; import {View} from 'react-native'; @@ -23,9 +24,27 @@ function GenericErrorPage() { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); - const {resetBoundary} = useErrorBoundary(); + const refresh = () => { + const lastRefreshTimestamp = JSON.parse(sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_REFRESH_TIMESTAMP) ?? 'null') as string; + + if (lastRefreshTimestamp === null || differenceInMilliseconds(Date.now(), Number(lastRefreshTimestamp)) > CONST.ERROR_WINDOW_RELOAD_TIMEOUT) { + resetBoundary(); + sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.LAST_REFRESH_TIMESTAMP, Date.now().toString()); + + return; + } + + window.location.reload(); + sessionStorage.removeItem(CONST.SESSION_STORAGE_KEYS.LAST_REFRESH_TIMESTAMP); + }; + + const refreshAndSignOut = () => { + Session.signOutAndRedirectToSignIn(); + refresh(); + }; + return ( {({paddingBottom}) => ( @@ -59,16 +78,13 @@ function GenericErrorPage() {