Skip to content
Merged
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
24 changes: 23 additions & 1 deletion src/pages/Search/SearchMoneyRequestReportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
getReportAction,
isMoneyRequestAction,
} from '@libs/ReportActionsUtils';
import {isValidReportIDFromPath} from '@libs/ReportUtils';
import {isMoneyRequestReport, isValidReportIDFromPath} from '@libs/ReportUtils';
import {isDefaultAvatar, isLetterAvatar, isPresetAvatar} from '@libs/UserAvatarUtils';
import Navigation from '@navigation/Navigation';
import ReactionListWrapper from '@pages/inbox/ReactionListWrapper';
Expand Down Expand Up @@ -65,10 +65,32 @@
const reportIDFromRoute = getNonEmptyStringOnyxID(route.params?.reportID);
const {currentSearchResults: snapshot} = useSearchContext();
Comment thread
paulnjs marked this conversation as resolved.
Resolved

const firstRenderRef = useRef(true);

const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {allowStaleData: true, canBeMissing: true});
const prevReport = usePrevious(report);

const isFocused = useIsFocused();

// Dismiss modal when the money request report is removed (e.g. deleted or merged).
useEffect(() => {

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.

This introduced #89177. The report-removal detection effect watches report but doesn't guard against route transitions. When reportIDFromRoute changes (e.g. via next/previous arrows), the new report data hasn't loaded into Onyx yet, so report is momentarily undefined. The effect misinterprets this as the report being removed and calls Navigation.dismissModal(). Fixed in #89150 by tracking prevReportIDFromRoute and bailing out early when the route just changed.

// Skip first run so we don't dismiss on mount when report may still be loading.
if (firstRenderRef.current) {
firstRenderRef.current = false;
return;
}

// Report is gone now but we had a money request report before → it was removed.
const isRemovalExpectedForReportType = !report && isMoneyRequestReport(prevReport);

if (isRemovalExpectedForReportType) {

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.

Can you leave a comment explaining why this is necessary? For whoever is looking at this code later

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.

@paulnjs Friendly bump!

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.

@pecanoro Oh, thanks for reminding me! I updated.

if (!isFocused) {
return;
}
Navigation.dismissModal();
}
}, [report]);

Check warning on line 92 in src/pages/Search/SearchMoneyRequestReportPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useEffect has missing dependencies: 'isFocused' and 'prevReport'. Either include them or remove the dependency array

useEffect(() => {
// Update last visit time when the expense super wide RHP report is focused
if (!reportIDFromRoute || !isFocused || route.name !== SCREENS.RIGHT_MODAL.EXPENSE_REPORT) {
Expand Down
Loading