diff --git a/src/Expensify.tsx b/src/Expensify.tsx index de21defd5a2b..dd64fbca1ed4 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -106,6 +106,7 @@ function Expensify() { const [currentOnboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, {canBeMissing: true}); const [currentOnboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE, {canBeMissing: true}); const [onboardingInitialPath] = useOnyx(ONYXKEYS.ONBOARDING_LAST_VISITED_PATH, {canBeMissing: true}); + const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: false}); useDebugShortcut(); usePriorityMode(); @@ -211,12 +212,12 @@ function Expensify() { // If the app is opened from a deep link, get the reportID (if exists) from the deep link and navigate to the chat report Linking.getInitialURL().then((url) => { setInitialUrl(url as Route); - Report.openReportFromDeepLink(url ?? '', currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath); + Report.openReportFromDeepLink(url ?? '', currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath, allReports); }); // Open chat report from a deep link (only mobile native) Linking.addEventListener('url', (state) => { - Report.openReportFromDeepLink(state.url, currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath); + Report.openReportFromDeepLink(state.url, currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath, allReports); }); if (CONFIG.IS_HYBRID_APP) { HybridAppModule.onURLListenerAdded(); diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 5e47526932c5..3c058f68337f 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -3376,6 +3376,7 @@ function openReportFromDeepLink( currentOnboardingPurposeSelected: OnyxEntry, currentOnboardingCompanySize: OnyxEntry, onboardingInitialPath: OnyxEntry, + reports: OnyxCollection, ) { const reportID = getReportIDFromLink(url); const isAuthenticated = hasAuthToken(); @@ -3457,7 +3458,7 @@ function openReportFromDeepLink( const navigateHandler = (reportParam?: OnyxEntry) => { // Check if the report exists in the collection - const report = reportParam ?? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; + const report = reportParam ?? reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; // If the report does not exist, navigate to the last accessed report or Concierge chat if (reportID && (!report?.reportID || report.errorFields?.notFound)) { const lastAccessedReportID = findLastAccessedReport(false, shouldOpenOnAdminRoom(), undefined, reportID)?.reportID; @@ -3474,7 +3475,11 @@ function openReportFromDeepLink( }; // If we log with deeplink with reportID and data for this report is not available yet, // then we will wait for Onyx to completely merge data from OpenReport API with OpenApp API in AuthScreens - if (reportID && !isAuthenticated && !allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]) { + if ( + reportID && + !isAuthenticated && + (!reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] || !reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.reportID) + ) { const reportConnection = Onyx.connect({ key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, // eslint-disable-next-line rulesdir/prefer-early-return