Skip to content

Fix RHP dismissal during report navigation with key-based wrapper#88113

Closed
leshniak wants to merge 1 commit intoExpensify:mainfrom
callstack-internal:fix/rhp-dismissal-during-hydration
Closed

Fix RHP dismissal during report navigation with key-based wrapper#88113
leshniak wants to merge 1 commit intoExpensify:mainfrom
callstack-internal:fix/rhp-dismissal-during-hydration

Conversation

@leshniak
Copy link
Copy Markdown
Contributor

When navigating between expense reports via prev/next arrows, the RHP closes unexpectedly because setParams updates reportIDFromRoute immediately but Onyx briefly returns undefined for the new report. The dismissal effect misinterprets this transient state as a report deletion and calls dismissModal.

Explanation of Change

Split SearchMoneyRequestReportPage into an outer wrapper that passes key={reportIDFromRoute} and an inner SearchMoneyRequestReportPageContent. Each arrow click remounts the inner component with a clean slate — all hooks and refs reset naturally without manual tracking.

The dismissal effect uses a mount-scoped hasEverHadReportRef — it starts false on each remount, so the transient undefined during Onyx hydration cannot trigger dismissal. Once the report loads, the ref becomes true. If the report is later deleted (becomes undefined), we dismiss — preserving the existing behavior. The isMoneyRequestReport check from the original code was dropped since this page only renders money request reports.

Also adds a hydration guard in shouldShowAccessErrorPage: when reportIDFromRoute is set but reportID hasn't resolved from Onyx yet and report actions haven't loaded, the error page is suppressed — showing the skeleton loader instead of "Hmm... it's not there". The guard is bounded by hasLoadedReportActionsForAccessError so genuinely non-existent reports still show the error once loading completes.

This also removes both usePrevious calls from the component, making it React Compiler compliant.

Fixed Issues

$ #87784
PROPOSAL:

Tests

  1. Navigate to Search → Reports (expense reports)
  2. Click on any expense report row to open it in the RHP
  3. Verify the RHP opens and shows the report content (not "Hmm... it's not there")
  4. Use the prev/next navigation arrows to navigate between reports
  5. Verify the RHP stays open and shows a skeleton loader briefly during transitions
  6. Verify no unexpected dismissal occurs during rapid arrow clicking
  • Verify that no errors appear in the JS console

Offline tests

  1. Open an expense report via search arrows while online
  2. Go offline
  3. Use prev/next arrows to navigate between cached reports
  4. Verify navigation works for reports already loaded in Onyx
  5. Verify no crash or unexpected dismissal occurs

QA Steps

Same as Tests above.

  • Verify that no errors appear in the JS console

When navigating between expense reports using prev/next arrows, the RHP
would close because the dismissal effect detected report as undefined
during Onyx key transition and incorrectly triggered dismissModal.

Split SearchMoneyRequestReportPage into outer wrapper with
key={reportIDFromRoute} and inner content component. Each arrow click
remounts with clean state. A mount-scoped hasEverHadReportRef ensures
dismissal only fires after report has loaded then disappeared (deletion),
not during initial hydration gap. Hydration guard in shouldShowAccessErrorPage
suppresses the not-found page while Onyx resolves.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@leshniak leshniak requested review from a team as code owners April 16, 2026 13:33
@melvin-bot melvin-bot Bot requested review from a team, abdulrahuman5196 and trjExpensify and removed request for a team April 16, 2026 13:33
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented Apr 16, 2026

@abdulrahuman5196 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot Bot requested review from Julesssss and aimane-chnaif and removed request for a team April 16, 2026 13:33
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented Apr 16, 2026

@aimane-chnaif @Julesssss One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 16, 2026

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/pages/Search/SearchMoneyRequestReportPage.tsx 0.00% <0.00%> (ø)
... and 266 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant