Skip to content

Commit 523b54b

Browse files
authored
Merge pull request Expensify#89150 from callstack-internal/bugfix/money-request-report-navigation-dismiss
Fix modal dismiss on report route change in SearchMoneyRequestReportPage
2 parents c99f4df + 4c5c648 commit 523b54b

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/pages/Search/SearchMoneyRequestReportPage.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
8787

8888
const [parentReportLoadingState] = useOnyx(`${ONYXKEYS.COLLECTION.RAM_ONLY_REPORT_LOADING_STATE}${report?.parentReportID}`);
8989
const prevReport = usePrevious(report);
90+
const prevReportIDFromRoute = usePrevious(reportIDFromRoute);
9091
const {email: currentUserEmail, accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
9192
const isFocused = useIsFocused();
9293

@@ -98,6 +99,11 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
9899
return;
99100
}
100101

102+
// Route just changed — new report data may not be loaded yet, so don't treat as removal.
103+
if (prevReportIDFromRoute !== reportIDFromRoute) {
104+
return;
105+
}
106+
101107
// Report is gone now but we had a money request report before → it was removed.
102108
const isRemovalExpectedForReportType = !report && isMoneyRequestReport(prevReport);
103109

@@ -107,7 +113,7 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
107113
}
108114
Navigation.dismissModal();
109115
}
110-
}, [report, isFocused, prevReport]);
116+
}, [report, isFocused, prevReport, prevReportIDFromRoute, reportIDFromRoute]);
111117

112118
useEffect(() => {
113119
// Update last visit time when the expense super wide RHP report is focused
@@ -204,7 +210,6 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
204210

205211
// Tracks initial mount to ensure openReport is called once for multi-transaction reports
206212
const isInitialMountRef = useRef(true);
207-
const prevReportIDFromRoute = usePrevious(reportIDFromRoute);
208213

209214
useEffect(() => {
210215
// Reset flag when reportID changes (screen stays mounted but navigates to different report)

0 commit comments

Comments
 (0)