From 4e953a313e3aaf7437b90d9f42094e9029118425 Mon Sep 17 00:00:00 2001 From: daledah Date: Fri, 7 Feb 2025 14:02:44 +0700 Subject: [PATCH 1/4] fix: remove flashing effect when opening a report --- src/libs/Navigation/NavigationRoot.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index df42aa04a12e2..693e905199743 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -174,9 +174,9 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady, sh const activeWorkspaceID = getPolicyIDFromState(state as NavigationState); // Performance optimization to avoid context consumers to delay first render setTimeout(() => { - currentReportIDValue?.updateCurrentReportID(state); setActiveWorkspaceID(activeWorkspaceID); }, 0); + currentReportIDValue?.updateCurrentReportID(state); parseAndLogRoute(state); // We want to clean saved scroll offsets for screens that aren't anymore in the state. From 674fe582ba332d6d45bda7c5d0af95024015a956 Mon Sep 17 00:00:00 2001 From: daledah Date: Thu, 20 Feb 2025 23:47:37 +0700 Subject: [PATCH 2/4] fix: use alternate solution --- src/hooks/useCurrentReportID.tsx | 9 +++++++-- src/libs/Navigation/NavigationRoot.tsx | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/hooks/useCurrentReportID.tsx b/src/hooks/useCurrentReportID.tsx index 9b6f25f834cd1..edb7f7b4b3999 100644 --- a/src/hooks/useCurrentReportID.tsx +++ b/src/hooks/useCurrentReportID.tsx @@ -1,6 +1,9 @@ import type {NavigationState} from '@react-navigation/native'; import React, {createContext, useCallback, useContext, useMemo, useState} from 'react'; +import {useOnyx} from 'react-native-onyx'; import Navigation from '@libs/Navigation/Navigation'; +import {getReportIDFromLink} from '@libs/ReportUtils'; +import ONYXKEYS from '@src/ONYXKEYS'; type CurrentReportIDContextValue = { updateCurrentReportID: (state: NavigationState) => void; @@ -16,6 +19,8 @@ const CurrentReportIDContext = createContext function CurrentReportIDContextProvider(props: CurrentReportIDContextProviderProps) { const [currentReportID, setCurrentReportID] = useState(''); + const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH); + const lastAccessReportFromPath = getReportIDFromLink(lastVisitedPath ?? null); /** * This function is used to update the currentReportID @@ -45,9 +50,9 @@ function CurrentReportIDContextProvider(props: CurrentReportIDContextProviderPro const contextValue = useMemo( (): CurrentReportIDContextValue => ({ updateCurrentReportID, - currentReportID, + currentReportID: lastAccessReportFromPath ?? currentReportID, }), - [updateCurrentReportID, currentReportID], + [updateCurrentReportID, currentReportID, lastAccessReportFromPath], ); return {props.children}; diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index ec727dfc53fdf..93c6fc355aea4 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -197,7 +197,10 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady, sh const currentRoute = navigationRef.getCurrentRoute(); Firebase.log(`[NAVIGATION] screen: ${currentRoute?.name}, params: ${JSON.stringify(currentRoute?.params ?? {})}`); - currentReportIDValue?.updateCurrentReportID(state); + // Performance optimization to avoid context consumers to delay first render + setTimeout(() => { + currentReportIDValue?.updateCurrentReportID(state); + }, 0); parseAndLogRoute(state); // We want to clean saved scroll offsets for screens that aren't anymore in the state. From d34506c9796b72c02b3b11ff3711f779c9075703 Mon Sep 17 00:00:00 2001 From: daledah Date: Fri, 21 Feb 2025 12:36:44 +0700 Subject: [PATCH 3/4] fix: replace nullish coalescing operator with OR --- src/hooks/useCurrentReportID.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/useCurrentReportID.tsx b/src/hooks/useCurrentReportID.tsx index edb7f7b4b3999..e9f5046048f98 100644 --- a/src/hooks/useCurrentReportID.tsx +++ b/src/hooks/useCurrentReportID.tsx @@ -50,7 +50,7 @@ function CurrentReportIDContextProvider(props: CurrentReportIDContextProviderPro const contextValue = useMemo( (): CurrentReportIDContextValue => ({ updateCurrentReportID, - currentReportID: lastAccessReportFromPath ?? currentReportID, + currentReportID: lastAccessReportFromPath || currentReportID, }), [updateCurrentReportID, currentReportID, lastAccessReportFromPath], ); From 09de1089ced51f3dc6b7cdd937229dc3e0530eeb Mon Sep 17 00:00:00 2001 From: daledah Date: Fri, 28 Feb 2025 16:13:22 +0700 Subject: [PATCH 4/4] fix: change logics to avoid regression --- src/hooks/useCurrentReportID.tsx | 4 +++- src/hooks/useReportIDs.tsx | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hooks/useCurrentReportID.tsx b/src/hooks/useCurrentReportID.tsx index e9f5046048f98..3af6f3b42c56a 100644 --- a/src/hooks/useCurrentReportID.tsx +++ b/src/hooks/useCurrentReportID.tsx @@ -8,6 +8,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; type CurrentReportIDContextValue = { updateCurrentReportID: (state: NavigationState) => void; currentReportID: string | undefined; + currentReportIDFromPath: string | undefined; }; type CurrentReportIDContextProviderProps = { @@ -50,7 +51,8 @@ function CurrentReportIDContextProvider(props: CurrentReportIDContextProviderPro const contextValue = useMemo( (): CurrentReportIDContextValue => ({ updateCurrentReportID, - currentReportID: lastAccessReportFromPath || currentReportID, + currentReportID, + currentReportIDFromPath: lastAccessReportFromPath || undefined, }), [updateCurrentReportID, currentReportID, lastAccessReportFromPath], ); diff --git a/src/hooks/useReportIDs.tsx b/src/hooks/useReportIDs.tsx index 87e417b1f8bee..7a6ccea331ab2 100644 --- a/src/hooks/useReportIDs.tsx +++ b/src/hooks/useReportIDs.tsx @@ -64,7 +64,7 @@ function ReportIDsContextProvider({ const {shouldUseNarrowLayout} = useResponsiveLayout(); const {accountID} = useCurrentUserPersonalDetails(); const currentReportIDValue = useCurrentReportID(); - const derivedCurrentReportID = currentReportIDForTests ?? currentReportIDValue?.currentReportID; + const derivedCurrentReportID = currentReportIDForTests ?? currentReportIDValue?.currentReportIDFromPath ?? currentReportIDValue?.currentReportID; const {activeWorkspaceID} = useActiveWorkspace(); const policyMemberAccountIDs = useMemo(() => getPolicyEmployeeListByIdWithoutCurrentUser(policies, activeWorkspaceID, accountID), [policies, activeWorkspaceID, accountID]);