App icon indicating copy to clipboard operation
App copied to clipboard

[$250] Reports- Tap back button on RHP navigate to thread instead of Spend - Expenses

Open applause-bot[bot] opened this issue 1 week ago • 71 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.5.53-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://github.com/Expensify/App/pull/104926 Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team Bug source: Pull Request QA execution Device used: Windows 11 Chrome App Component: Chat Report View

Action Performed:

Preconditions:

  • Account with some expenses with comment inside
  1. Open https://staging.new.expensify.com/
  2. Navigate to Spend
  3. Click on 1 expense with atleast 1 comment inside
  4. Right click on the comment
  5. Click on "Reply in thread"
  6. Click on the parent comment in chat history
  7. Click on "<" back button on the expense detail RHP

Expected Result:

Verify that the Spend > Expenses list shows again.

Actual Result:

User is navigated to comment thread

Workaround:

Unknown

Platforms:

  • [x] Android: App
  • [ ] Android: mWeb Chrome
  • [x] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [ ] MacOS: Chrome Safari

Screenshots/Videos

https://github.com/user-attachments/assets/0b339e1b-d2d0-4ee6-a471-65c1eace5885

View all open jobs on GitHub

Applause Internal Information Exported by: Julia Ponikarchuk Bug ID: 7322575

Upwork Automation - Do Not Edit

applause-bot[bot] avatar Nov 24 '26 05:11 applause-bot[bot]

While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/5f7e8c84105c84b45d22db98be90a54503b6b053695ee98d60d1e422cfbf5f34

applause-bot[bot] avatar Nov 24 '26 05:11 applause-bot[bot]

Triggered auto assignment to Contributor-plus team member for initial proposal review - @samranahm (External)

Job added to Upwork: https://www.upwork.com/jobs/~022125097486422596139

🤖 Web test steps verification results: ⚠️ partial

Created a disposable $1.07 expense and comment. Verification stopped at an unsupported right-click operation, so the reported navigation bug remains unverified. Disposable expense opened with its saved parent comment

Step Status
Open Spend > ExpensesInitially empty; the disposable expense appeared after creation.
Spend > Expenses showing no expenses
✅
Open an expense with an existing commentReopened the expense and confirmed its saved comment.
Disposable expense opened with its saved parent comment
✅
Right-click comment → Reply in threadDriver returned UNSUPPORTED_OPERATION for secondary-click; hovering exposed no reply action.
❌
Click the parent commentBlocked before entering the thread.
❌
Click expense header Back → Spend > ExpensesNot executed from the required thread-origin state.
❌

Preliminary analysis — low confidence

Suspected mechanism: Parent-comment navigation can open another expense panel above the thread. Its Back button then pops that panel, revealing the thread instead of Spend.

Code evidence and important counterevidence

However, the helper already checks whether the original expense is immediately below the thread. If found, it updates that expense and pops the thread rather than opening another panel: ReportUtils.ts:12440–12452. That should prevent the reported behavior in the straightforward stack.

The unresolved question is why this protection misses in the affected flow. A different stack shape or deployed implementation remains possible.

The QA-linked unsafe-assertion refactor does not establish causation: its relevant header changes are type-only, and the Back behavior already existed before that merge.

Required before recommending a fix: Capture the active panel stack, ancestor report ID, and selected navigation branch immediately before and after clicking the parent comment. This will distinguish a missed existing-expense match from a different navigation failure. Add regression coverage for the complete sequence through the final Back action; reverting type annotations is not supported by the evidence.


view run · view recording

MelvinBot avatar Nov 24 '26 05:11 MelvinBot

Proposal

Reproduced on staging web. The route IDs show the cause directly:

  1. Spend > Expenses → expense: /search/view/6668534542846014?anchorTransactionID=... (the expense report).
  2. Comment → Reply in thread: /search/view/5808396084513355 (the thread).
  3. Click the parent comment: a new screen /search/view/8951406895024852/<reportActionID>?backTo=SearchReport is pushed. 8951406895024852 is the expense's one-transaction thread, not the expense report below.
  4. < → back on the thread (5808396084513355) instead of Spend > Expenses.

What is the root cause of that problem?

When the user clicks the parent comment, AncestorReportActionItem calls navigateToLinkedReportAction. In the RHP it already has a guard for this exact flow: if the route under the thread is the ancestor's report, it updates that route and pops the thread instead of pushing a new screen:

https://github.com/Expensify/App/blob/main/src/libs/ReportUtils.ts#L12440-L12452

The guard misses because of one-expense reports. Opening an expense from Spend > Expenses opens SEARCH_REPORT with the expense report's ID (/search/view/<expenseReportID>?anchorTransactionID=...). In that combined view, comments are posted to the one-transaction thread, not the expense report (useComposerReportData → getOneTransactionThreadReportID). So:

  • ancestor.report.reportID is the transaction thread ID.
  • routeBelow.params.reportID is the expense report ID, which is the transaction thread's parent.

They never match. The code falls through to Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: <transaction thread>, ...})) and pushes a third screen on top of the thread. Pressing < on that screen pops back to the thread, which is the reported bug.

What changes do you think we should make in order to solve the problem?

In navigateToLinkedReportAction, make the existing "route below" guard also recognize the expense report that displays the ancestor transaction thread:

  1. Compute isAncestorShownInRouteBelow:
    • true if routeBelowParams.reportID === ancestor.report.reportID (today's case);
    • or if the ancestor is a transaction thread (isReportTransactionThread(ancestor.report)) and routeBelowParams.reportID === ancestor.report.parentReportID, i.e. the screen below is the one-expense report that renders that thread's actions.
  2. When it's true, keep today's behaviour: setParams({reportActionID}) on the route below so the combined view scrolls to and highlights the parent comment, then Navigation.goBack() to pop the thread.
  3. Everything else is unchanged:
    • Multi-expense reports and other ancestors still push SEARCH_REPORT as today.
    • The wide-layout (non-RHP) branch is unchanged.

After the fix: thread → click parent comment → back on the expense with the comment highlighted → < returns to Spend > Expenses.

Tests (unit tests for navigateToLinkedReportAction with a mocked RHP state):

  • Route below = expense report and ancestor = its one-transaction thread: setParams on the route below plus goBack, and no navigate.
  • Route below = same report ID as the ancestor: same as above (existing behaviour preserved).
  • Route below is an unrelated report: navigate(SEARCH_REPORT) as today.
  • Ancestor is a non-transaction-thread report whose parentReportID matches the route below: still navigate (the new branch only applies to transaction threads).

What alternative solutions did you explore? (Optional)

  • Change the backTo / back-button handling in ReportHeader so < skips the thread. That treats the symptom: the extra screen would still be pushed, and the stack would keep a duplicate expense screen.
  • Navigate with the expense report ID instead of the thread ID in the fallback. That still pushes a duplicate of the screen already below. Reusing the route below, like the existing guard does, is cleaner.

Xch4rt avatar Nov 24 '26 05:11 Xch4rt

Proposal

What is the root cause of that problem?

The "already open below" guard in navigateToLinkedReportAction compares the wrong report IDs when an expense was opened from Spend > Expenses and belongs to a single-expense report, so clicking the parent comment pushes a duplicate RHP screen instead of popping back.

  1. Spend opens the expense report, not the transaction thread. For a single-expense report, the Spend list keeps reportID = transactionItem.reportID (the expense report) and only switches to reportAction.childReportID (the transaction thread) for self-DM or multi-expense reports: Search/index.tsx#L787-L794. It then opens SEARCH_REPORT with that expense report ID: Search/index.tsx#L898-L910.
  2. Comments are stored on the transaction thread. In that combined single-expense view, the composer writes comments to effectiveTransactionThreadReportID ?? reportID: useComposerSubmit.ts#L51-L52 via useComposerReportData.ts#L32-L35. "Reply in thread" therefore creates a child of the transaction thread and pushes it as another SEARCH_REPORT onto the same RHP (Report/index.ts#L3055-L3061), leaving the RHP stack as [SEARCH_REPORT(expenseReportID), SEARCH_REPORT(commentThreadID)].
  3. The guard misses. Clicking the parent comment (AncestorReportActionItem.tsx#L124-L139) calls navigateToLinkedReportAction, whose guard only goes back when routeBelowParams.reportID === ancestor.report.reportID (ReportUtils.ts#L12440-L12452). Here ancestor.report is the transaction thread, whereas routeBelow holds its parent expense report, so the IDs differ and the fallback pushes SEARCH_REPORT({reportID: transactionThreadID, reportActionID, backTo: SEARCH_REPORT}) (ReportUtils.ts#L12454-L12461).
  4. The duplicate screen is not redirected away. OneTransactionThreadRedirectHandler deliberately skips routes that include reportActionID (OneTransactionThreadRedirectHandler.tsx#L86-L91), so the pushed transaction-thread screen remains above the comment thread. Its header Back button sees backTo === SCREENS.RIGHT_MODAL.SEARCH_REPORT and calls plain Navigation.goBack() (ReportHeader.tsx#L65-L68), returning to the comment thread instead of Spend > Expenses.

This also explains why the guard already works for multi-expense reports and self-DM expenses: in those flows Spend opens the transaction thread itself, so the IDs match.

What changes do you think we should make in order to solve the problem?

In navigateToLinkedReportAction (ReportUtils.ts#L12440-L12452), extend the "ancestor is already open below" check to also recognize the combined single-expense report case:

  • Keep the existing exact match (routeBelowParams.reportID === ancestor.report.reportID).
  • Also treat routeBelow as a match when routeBelowParams.reportID === ancestor.report.parentReportID and ancestor.report is specifically that parent's one-transaction thread, verified with the existing isOneTransactionThread(ancestor.report, parentReport, parentReportAction) helper (ReportUtils.ts#L3053-L3071) using the Onyx report and parent report action lookups already in ReportUtils. Checking isOneTransactionThread rather than only isReportTransactionThread is critical so a multi-expense parent report sitting below in the RHP (which does not render its child transaction threads' comments inline) does not false-match and pop away from the transaction thread.
  • When either condition matches, keep the existing behavior: call setParams({reportActionID}) on routeBelow so the combined single-expense view scrolls to and highlights the parent comment, then call Navigation.goBack(). The RHP stack cleanly returns to [SEARCH_REPORT(expenseReportID)], and tapping < closes the RHP back to Spend > Expenses.

No changes are needed in ReportHeader, OneTransactionThreadRedirectHandler, or Search/index.tsx, preserving multi-expense/self-DM flows, reportActionID deep links, and the non-RHP (isInNarrowPaneModal === false) path.

Add unit test coverage for navigateToLinkedReportAction verifying:

  • RHP stack [SEARCH_REPORT(singleExpenseParentReport), SEARCH_REPORT(commentThread)] with a one-transaction-thread ancestor calls setParams + goBack and does not call navigate.
  • RHP stack where routeBelow is a multi-expense parent report (not a one-transaction thread) still falls through to navigate instead of popping back to the parent report.
  • Existing exact-ID match and unrelated-report cases remain unchanged.

What alternative solutions did you explore? (Optional)

  • Checking only isReportTransactionThread(ancestor.report) with parentReportID: Rejected because any transaction thread under a multi-expense report also passes isReportTransactionThread, which would falsely pop back to a multi-expense parent report that does not render that transaction's comments inline.
  • Letting OneTransactionThreadRedirectHandler redirect even when reportActionID is set: Rejected because the redirected screen would still sit above the comment thread on the RHP stack (so Back would still land on the thread) and it would regress comment deep links into one-transaction threads.
  • Altering ReportHeader Back behavior for backTo === SEARCH_REPORT: Rejected because it masks the duplicate screen on the stack and would break legitimate report-to-report back navigation in Search.

colton-summerlin avatar Nov 24 '26 05:11 colton-summerlin

@samranahm Melvin's analysis leaves open why the route-below check in navigateToLinkedReportAction misses, and the answer is the IDs: for a one-expense report, Spend opens the RHP on the expense report's reportID, not the transaction thread's:

https://github.com/Expensify/App/blob/d7c37c01c1f789576fce663d34cc8255e4a55f51/src/components/Search/index.tsx#L787-L795

Comments typed in that combined view are written to the transaction thread instead:

https://github.com/Expensify/App/blob/d7c37c01c1f789576fce663d34cc8255e4a55f51/src/pages/inbox/report/ReportActionCompose/useComposerSubmit.ts#L51-L52

So in the reply thread ancestor.report is the transaction thread, the reportID comparison fails, and the fallback pushes a SEARCH_REPORT for it with backTo: SCREENS.RIGHT_MODAL.SEARCH_REPORT, whose Back pops straight to the thread; I tested this locally — after clicking the parent comment the RHP stack is [expense report, thread, transaction thread], and Back lands on the thread. Treating the route below as a match when it is the one-expense parent of ancestor.report (its parentReportID) and just popping back to it fixes this inside that one helper, without touching Search or the composer.

Happy to put up a full proposal for this if that's useful.

yusufdeveloper2903 avatar Nov 24 '26 05:11 yusufdeveloper2903

Proposal

Please re-state the problem that we are trying to solve in this issue.

From Spend > Expenses, opening an expense that has a comment, replying in thread, clicking the parent comment, and then tapping the "<" back button on the expense detail RHP takes the user to the comment thread instead of back to the Spend > Expenses list.

What is the root cause of that problem?

The "ancestor is already open below" guard in navigateToLinkedReportAction (src/libs/ReportUtils.ts) only compares exact report IDs, and it misses in the one-expense case. Verified on baseline e91964cb:

  1. Spend opens the expense report, not the transaction thread, for a one-expense report. Search/index.tsx only switches reportID to the transaction thread's childReportID for self-DM or multi-expense reports, so a one-expense report opens SEARCH_REPORT with the expense report's ID.
  2. Comments in that combined view are written to the transaction thread, not the expense report (useComposerReportData resolves effectiveTransactionThreadReportID, and useComposerSubmit targets it). "Reply in thread" therefore pushes a second SEARCH_REPORT for the comment thread on top of the expense report.
  3. Clicking the parent comment calls navigateToLinkedReportAction with ancestor.report set to the transaction thread. The RHP guard only pops back when routeBelowParams.reportID === ancestor.report.reportID, but the route below holds the transaction thread's parent expense report, so the IDs differ and the code falls through to pushing a third screen: SEARCH_REPORT for the transaction thread with backTo: SEARCH_REPORT.
  4. That third screen keeps its reportActionID, so OneTransactionThreadRedirectHandler deliberately skips redirecting it, and its header Back button sees backTo === SEARCH_REPORT and calls plain Navigation.goBack(), landing on the comment thread. That is the reported bug.

What changes do you think we should make in order to solve the problem?

In navigateToLinkedReportAction, extend the RHP "already open below" guard to also recognize the one-expense parent below, in src/libs/ReportUtils.ts only:

  1. Keep the existing exact match (routeBelowParams.reportID === ancestor.report.reportID), with its current behaviour of setting reportActionID on the route below and going back.
  2. Also treat the route below as a match when routeBelowParams.reportID === ancestor.report.parentReportID and the ancestor is that parent's one-transaction thread, verified with the existing isOneTransactionThread(ancestor.report, parentReport, parentReportAction, isOffline) helper. The parent report and parent report action are looked up the same way getDisplayedReportID already does in this file (deprecatedAllReports and getReportAction), and isOffline is passed through for the deleted-IOU offline edge. Using isOneTransactionThread rather than only isReportTransactionThread matters: any transaction thread passes isReportTransactionThread, so that check alone would wrongly pop back to a multi-expense parent report that does not render the thread's comments inline. With the stricter check, a multi-expense parent still falls through to pushing a new screen, as today.
  3. When the one-transaction parent matches, just call Navigation.goBack() with no setParams. The parent comment is an action on the transaction thread, not on the expense report, so setting its reportActionID on the expense report route cannot scroll to or highlight it: LinkedActionNotFoundGate looks the action up only in the expense report's actions and finds nothing, and neither scroll hook finds it in the expense report's rendered actions, so there is no scroll target. Popping back without the param lands on the expense report as it was, and tapping "<" there returns to Spend > Expenses.

No changes are needed in ReportHeader, OneTransactionThreadRedirectHandler, or Search/index.tsx, and the non-RHP (wide layout) branch is unchanged.

Tests added in tests/unit/NavigateToLinkedReportActionTest.ts (Given/When/Then style, RHP stack mocked through navigationRef): the one-expense parent below pops back with no navigate and no setParams; a multi-expense parent below still pushes a new screen for the thread; the existing exact-ID match still sets reportActionID and pops back; an unrelated route below still pushes a new screen; and a missing parent report in Onyx safely falls through to pushing a new screen.

Evidence: the 5 new tests pass (5/5) and the first test fails on the clean baseline (the bug reproduces: navigate is called instead of goBack). oxlint reports 0 errors on the new test file and no new errors on ReportUtils.ts (137 pre-existing errors on the file before and after the change, none on the changed lines); spell check clean; React Compiler compliance check passed. Full typecheck could not be run on this machine: the TypeScript compiler process is killed before emitting diagnostics (a known limitation of this 6 GB VM; no diagnostics were emitted before the process was killed); the changes keep their declared types and the type-aware lint rules pass on all changed files.

This pops back to the expense report as it was, without scrolling to or highlighting the parent comment, which lives on the transaction thread.

What alternative solutions did you explore? (Optional)

  1. Checking only isReportTransactionThread(ancestor.report) with parentReportID: Rejected because any transaction thread under a multi-expense report also passes isReportTransactionThread, which would falsely pop back to a multi-expense parent report that does not render that transaction's comments inline. The new unit test for the multi-expense parent proves this distinction.
  2. Setting reportActionID on the expense report route below so the combined view scrolls to the parent comment: Rejected because the comment is not in the expense report's actions collection, so no scroll target exists: LinkedActionNotFoundGate looks it up only in the expense report's actions and finds nothing, and neither scroll hook finds it in the expense report's rendered actions. Popping back without the param avoids that churn.
  3. Altering ReportHeader Back behavior for backTo === SEARCH_REPORT: Rejected because it masks the duplicate screen on the stack and would break legitimate report-to-report back navigation in Search.
  4. Letting OneTransactionThreadRedirectHandler redirect even when reportActionID is set: Rejected because the redirected screen would still sit above the comment thread on the RHP stack (so Back would still land on the thread) and it would regress comment deep links into one-transaction threads.

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~013b564a690d9bcdab

dankezo avatar Nov 24 '26 06:11 dankezo

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 24 '26 06:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue?

When opening an expense report from Spend > Expenses into the Right Hand Panel (RHP), replying in a comment thread, tapping the parent comment in chat history to return to the parent expense report, and then tapping the < back button in the header, the user is navigated back to the comment thread instead of returning to Spend > Expenses.

What is the root cause of that problem?

In src/pages/inbox/ReportHeader.tsx (lines 51–73):

const onBackButtonPress = (prioritizeBackTo = false, options?: {afterTransition?: () => void}) => {
    if (isInSidePanel) {
        closeSidePanel({afterTransition: options?.afterTransition});
        return;
    }
    if (backTo === SCREENS.RIGHT_MODAL.SEARCH_REPORT) {
        Navigation.goBack(undefined, options);
        return;
    }
    if (prioritizeBackTo && backTo) {
        Navigation.goBack(backTo as Route, options);
        return;
    }
    if (isInNarrowPaneModal) {
        Navigation.goBack(undefined, options);
        return;
    }
    if (backTo) {
        Navigation.goBack(backTo as Route, options);
        return;
    }
    Navigation.goBack(undefined, options);
};
  1. When opening the expense from Spend > Expenses, the RHP route params contain backTo pointing to the Spend route.
  2. When the user opens a comment thread, the thread is pushed onto the RHP navigation stack.
  3. When the user taps the parent comment link inside the thread, Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(parentReportID)) pushes a new instance of the parent report onto the RHP navigation stack without preserving the original backTo param.
  4. Furthermore, in onBackButtonPress, if (isInNarrowPaneModal) (lines 64–67) executes Navigation.goBack(undefined, options) before checking backTo. Because it performs an unparameterized Navigation.goBack(), it simply pops the topmost screen on the RHP stack, returning the user to the child thread previously pushed below it, rather than exiting the RHP to Spend > Expenses.

What changes do you think we should make in order to solve the problem?

  1. In src/pages/inbox/ReportHeader.tsx: When an expense report in RHP was opened from Spend/Search, respect backTo or dismiss the modal when pressing the back button from the root expense report:
const onBackButtonPress = (prioritizeBackTo = false, options?: {afterTransition?: () => void}) => {
    if (isInSidePanel) {
        closeSidePanel({afterTransition: options?.afterTransition});
        return;
    }
    if (backTo === SCREENS.RIGHT_MODAL.SEARCH_REPORT) {
        Navigation.goBack(undefined, options);
        return;
    }
    if (backTo) {
        Navigation.goBack(backTo as Route, options);
        return;
    }
    if (isInNarrowPaneModal) {
        Navigation.goBack(undefined, options);
        return;
    }
    Navigation.goBack(undefined, options);
};
  1. When navigating from a thread to its parent report via header or parent comment press, navigate to the parent report using navigation state unwind or forward the original backTo parameter, ensuring the parent report retains its entry-point route metadata.

What alternative solutions did you explore? (Optional)?

Always calling Navigation.dismissModal() on RHP back press was considered, but would prevent navigating back from child sub-modals (e.g., editing description or category). Checking backTo before isInNarrowPaneModal ensures configured exit routes are honored while sub-screen back navigation remains intact.

What specific scenarios should we cover in automated tests to prevent reoccurrence?

Add automated unit tests in tests/ui/ReportHeaderTest.tsx:

  1. RHP Back Navigation with backTo: Verify that clicking the back button in ReportHeader on an RHP screen with backTo navigates to backTo even when isInNarrowPaneModal is true.
  2. Thread to Parent Unwind: Verify that navigating from Spend > Expenses into an expense, opening a thread, returning to the parent report, and clicking back returns to Spend > Expenses.

Contributor details?

  • Email: [email protected]
  • Upwork Profile: https://www.upwork.com/freelancers/~0131dae36abcf59374

kevinjosh10 avatar Nov 24 '26 16:11 kevinjosh10

@Xch4rt @colton-summerlin @dankezo @kevinjosh10 Thank you all for your interest in contributing to Expensify! Please only post proposal if Help Wanted label has been applied. Also, take a look at CONTRIBUTING.md to get familiar with the guidelines.

samranahm avatar Nov 24 '26 17:11 samranahm

@samranahm I traced the open question in Melvin's analysis: from Spend, a one-expense report opens on the expense report ID, but the parent comment lives on its transaction thread, so the route-below check in navigateToLinkedReportAction (ReportUtils.ts#L12448) never matches and an extra screen gets pushed on top of the thread.

I'd suggest matching the route below against getDisplayedReportID(ancestor.report.reportID) and just going back without setParams, since linking a thread comment on the expense report route empties its action list. I have this working with a test that fails on main, and I'll post a full proposal once Help Wanted is applied.

oqildev avatar Nov 24 '26 17:11 oqildev

@MelvinBot Post your proposal.

samranahm avatar Nov 26 '26 15:11 samranahm

Proposal

What is the root cause of that problem?

The parent-comment navigation fails to recognize that the expense is already open underneath the comment thread.

For a single-expense report, Spend opens the expense report, but its comments belong to the transaction thread. The existing navigation check compares those different report IDs, misses the already-open expense, and pushes another screen. Back then returns to the comment thread instead of Spend.

This confirms the report-ID mismatch identified in the contributor comments.

Code evidence

What changes do you think we should make in order to solve the problem?

Extend the existing reuse check in the navigation helper:

  1. Preserve the exact-ID match and its current behavior.
  2. Separately recognize when the underlying route displays the ancestor’s transaction thread, using the existing getDisplayedReportID helper, passing through the offline state.
  3. Require the parent’s transaction count to be one, preventing partially loaded multi-expense reports from matching accidentally.
  4. For this displayed-parent match, simply go back—without setting reportActionID. That comment belongs to the transaction thread, while the linked-action lookup reads the route report’s own actions.
  5. Leave other navigation paths unchanged.

This returns to the original expense panel; its next Back returns to Spend. It preserves the existing view rather than adding a new comment highlight.

Regression coverage: single-expense reuse without changing parameters; existing exact-ID behavior; unrelated or missing data; multi-expense parents—including partially loaded actions; self-DM expenses; offline handling; and the complete reported navigation sequence.

Verification: Code-traced against the current checkout; no new browser reproduction or tests were performed for this proposal.

What alternative solutions did you explore? (Optional)

Changing header Back behavior would hide the extra navigation rather than prevent it. Matching only the ancestor’s parent ID is too broad because multi-expense parents do not display transaction-thread comments inline.


Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/107808) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run

MelvinBot avatar Nov 26 '26 16:11 MelvinBot

@MelvinBot I tested your proposal locally, it fix the main issue but has one problem. When I click parent comment in thread to go back to expense report, the comment does not highlight anymore. Find the underlying problem and update your proposal.

samranahm avatar Nov 26 '26 19:11 samranahm

Proposal

Updated based on samranahm’s testing: returning to the expense must also scroll to and highlight the parent comment. My previous proposal incorrectly dropped that requirement.

What is the root cause of that problem?

There are two related problems:

  1. Navigation compares storage IDs rather than the displayed report. The expense panel uses the expense-report ID, while its inline comments belong to the transaction thread. The comparison misses and opens another panel.
  2. Linked-comment handling assumes the displayed report owns the comment. Simply going back removes the highlighting request. Restoring reportActionID alone is insufficient: pagination and missing-action validation look for that thread comment in the expense report’s actions.

The underlying inconsistency is that the combined expense view displays actions from two reports, but linked-action handling does not consistently distinguish where an action is displayed from which report owns it.

Supporting code evidence

What changes do you think we should make in order to solve the problem?

  1. Reuse the existing expense panel, retaining the narrowly scoped single-expense match from the previous proposal.
  2. Set the comment target before going back. Preserve the expense route and its existing parameters, but carry both the comment ID and its owning transaction-thread ID. The ancestor click already supplies both.
  3. Separate parent pagination from thread targeting. Discover the inline thread independently of the comment anchor. Apply the anchor to the owning thread’s page—not the expense report’s page—then combine the actions.
  4. Use the same owner for validation and fetching. Validate the alternate owner against the thread actually displayed by this expense. Fetch missing comments from that thread and wait for its loading result before clearing an unavailable target.
  5. Keep the existing highlight implementation. Ensure positioning runs when the target becomes available, including after loading. Clear any added targeting metadata when clearing the anchor.

No header Back change is needed.

Regression coverage: parent comment scrolls into view and highlights; subsequent Back reaches Spend; uncached/offscreen targets; genuinely unavailable comments; repeated parent-comment navigation; and unchanged exact-ID, multi-expense, self-DM, and offline behavior.

Verification: Source-level investigation only; the revised changes have not been implemented or browser-tested.

What alternative solutions did you explore? (Optional)

  • Go back without an anchor: fixes navigation but loses highlighting.
  • Restore only reportActionID: leaves pagination and validation reading the wrong collection.
  • Change header Back behavior: masks the extra panel rather than correcting navigation.

Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/107808) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run

MelvinBot avatar Nov 26 '26 19:11 MelvinBot

Melvin's direction is right, but the proposal is way broader than this bug needs. Ideally we should keep the change in navigateToLinkedReportAction and reuse the screen below when it shows the ancestor's one-transaction thread (getDisplayedReportID plus a transaction count of 1). Set only reportActionID there so we don't add a new route param.

Expected result: clicking the parent comment goes back to the expense and highlights the comment, and clicking the app back button then returns to "Spend" > "Expenses".

Opening the issue for External Contributors. Please check your solution locally and provide a POC video.

🆘 C+ Help Wanted

samranahm avatar Nov 27 '26 18:11 samranahm

🚨 Edited by proposal-police: This proposal was edited at 2026-11-28 08:56:27 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue?

On web, when opening a single-expense report from Spend > Expenses, replying in thread to a comment, and clicking the parent comment in the thread chat history to return to the expense, clicking the < (Back) button navigates back to the comment thread instead of returning to Spend > Expenses.

Reproduction

Environment:

  • Platform: Desktop Web
  • Build: Staging (staging.new.expensify.com)

Reproduction Nuance:

To reproduce, the expense must belong to a Workspace (or submitted report with 1 transaction). For personal/standalone IOU expenses, the expense report and transaction thread share the identical report ID, masking the defect. In Workspace reports, Expensify separates the Expense Report (R) and the Transaction Report (T). Clicking the parent comment targets T while the screen open below in RHP is R.

Steps to Reproduce:

  1. Ensure the account has a Workspace with at least one submitted expense containing a comment.
  2. Navigate to Spend > Expenses.
  3. Click on the Workspace expense (opens in RHP).
  4. Hover on the comment → click ... → click Reply in thread.
  5. In the thread panel on the right, click directly on the parent comment message text in the chat history.
  6. The panel transitions back to the expense report view.
  7. Click the < (Back) arrow button in the top-left of the header.
    • Bug (Before): Instead of returning to Spend > Expenses, the app navigates right back into the comment thread!
    • Expected (After): The RHP closes and cleanly returns the user to the Spend > Expenses list.

Video Evidence:


What is the root cause of that problem?

The bug is caused by a report ID mismatch when navigating back from a thread to a one-transaction parent expense in navigateToLinkedReportAction:

  1. Stack Mismatch in ReportUtils.ts:12668:
    When the thread is opened from a one-transaction Workspace expense report, the screen below the thread in the RHP stack is the Expense Report (routeBelowParams.reportID = R). However, the parent comment belongs to the underlying transaction thread report (ancestor.report.reportID = T).

    In src/libs/ReportUtils.ts:

    if (routeBelow?.key && routeBelowParams?.reportID === ancestor.report.reportID) {
        Navigation.setParams({reportActionID: ancestor.reportAction.reportActionID}, routeBelow.key, rhpState?.key);
        Navigation.goBack();
        return;
    }
    

    Because routeBelowParams.reportID (R) does not equal ancestor.report.reportID (T), this equality check fails.

  2. Unnecessary Screen Push with backTo: SearchReport:
    Because the check fails, the helper falls through to:

    Navigation.navigate(
        ROUTES.SEARCH_REPORT.getRoute({
            reportID: ancestor.report.reportID,
            reportActionID: ancestor.reportAction.reportActionID,
            backTo: SCREENS.RIGHT_MODAL.SEARCH_REPORT,
        }),
    );
    

    This pushes an extra SEARCH_REPORT screen on top of the RHP stack with backTo: SCREENS.RIGHT_MODAL.SEARCH_REPORT, resulting in an RHP stack of [R, thread, T].

  3. Back Button Trapping in ReportHeader.tsx:65-68:
    When the user taps the < (Back) button on that newly pushed screen, ReportHeader.tsx executes:

    if (backTo === SCREENS.RIGHT_MODAL.SEARCH_REPORT) {
        Navigation.goBack(undefined, options);
        return;
    }
    

    Navigation.goBack() simply pops T, uncovering the screen directly underneath it on the stack: the thread!


What changes do you think we should make in order to solve the problem?

  1. In src/libs/ReportUtils.ts inside navigateToLinkedReportAction: Check if routeBelow is the ancestor's parent report or one-transaction parent:

    const routeBelowReport = deprecatedAllReports?.[`${ONYXKEYS.COLLECTION.REPORT}${routeBelowParams?.reportID}`];
    const isRouteBelowParentReport =
        routeBelow?.key &&
        (routeBelowParams?.reportID === ancestor.report.reportID ||
            routeBelowParams?.reportID === ancestor.report.parentReportID ||
            (routeBelow?.name === SCREENS.RIGHT_MODAL.SEARCH_REPORT &&
                (isOneTransactionReport(routeBelowReport) || routeBelowParams?.reportID === getDisplayedReportID(ancestor.report.reportID, isOffline))));
    
    if (isRouteBelowParentReport && routeBelow?.key) {
        Navigation.setParams({reportActionID: ancestor.reportAction.reportActionID}, routeBelow.key, rhpState?.key);
        Navigation.goBack();
        return;
    }
    
  2. In src/pages/inbox/LinkedActionNotFoundGuard.tsx: For one-transaction reports, also query the inline transaction thread's actions (useOneTransactionThreadReportID) so that isLinkedActionUnavailable does not prematurely strip reportActionID for valid thread comments, keeping the amber highlight intact:

    const oneTransactionThreadReportID = useOneTransactionThreadReportID(reportIDFromRoute);
    const [linkedActionFromReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportIDFromRoute}`, {
        selector: (actions: OnyxEntry<ReportActions>) => getReportActionByIDSelector(actions, reportActionIDFromRoute),
    });
    const [linkedActionFromThread] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${oneTransactionThreadReportID}`, {
        selector: (actions: OnyxEntry<ReportActions>) => getReportActionByIDSelector(actions, reportActionIDFromRoute),
    });
    const linkedAction = linkedActionFromReport ?? linkedActionFromThread;
    

Why this resolves all requirements:

  • Comment Highlighting: Querying the transaction thread in LinkedActionNotFoundGuard ensures the comment is recognized as valid and maintains the amber highlight.
  • Clean Stack: Instead of pushing an extra screen [R, thread, T], it pops the thread, returning to routeBelow (R). Because routeBelow retains its original backTo pointing to Spend > Expenses, clicking < on routeBelow closes the RHP and returns straight to Spend > Expenses.
  • Multi-Transaction Safety: Reports with multiple transactions continue on their existing path without regressions.

What alternative solutions did you explore? (Optional)

  • Setting only reportActionID without updating LinkedActionNotFoundGuard:
    Leaves routeBelowParams.reportID pointing to R. Because the comment action belongs to T and not R, LinkedActionNotFoundGuard cannot resolve the action within R, triggering an auto-navigate that wipes reportActionID and loses the highlight. Extending the guard to check the inline thread preserves the highlight cleanly.
  • Handling back-navigation in ReportHeader.tsx:
    Attempting to check previous route history in ReportHeader.tsx is fragile and risks breaking normal back-navigation flows for threads and sub-screens across the app. Fixing the navigation dispatch at the source in navigateToLinkedReportAction is surgical and self-contained.

What specific scenarios should we cover in automated tests to prevent reoccurrence?

Add unit tests in tests/unit/ReportUtilsTest.ts:

  1. One-transaction parent report with thread:
    Simulate an RHP stack of [one-transaction report, thread] where ancestor.report is the transaction thread. Verify that calling navigateToLinkedReportAction calls Navigation.setParams({reportActionID}) on routeBelow and Navigation.goBack(), with zero calls to Navigation.navigate.
  2. Multi-transaction report (transactionCount > 1):
    Verify that when routeBelowReport has multiple transactions, navigateToLinkedReportAction continues to call Navigation.navigate with backTo: SCREENS.RIGHT_MODAL.SEARCH_REPORT.
  3. Add a test in LinkedActionNotFoundGuardTest.tsx verifying that a thread comment's reportActionID is not cleared when viewed from its one-transaction parent report.

Contributor details
Your Expensify account email: [email protected]
Upwork Profile Link: https://www.upwork.com/freelancers/~0131dae36abcf59374

kevinjosh10 avatar Nov 27 '26 18:11 kevinjosh10

🚨 Edited by proposal-police: This proposal was edited at 2026-11-30 11:45:46 UTC.

Proposal

Updated: added the transactionCount === 1 check you asked for, limited the reuse to the SEARCH_REPORT screen, and explained why the reused screen needs the thread's reportID for the highlight. Tests added for each.

Please re-state the problem that we are trying to solve in this issue.

Open a one-expense report from Spend > Expenses, reply in thread to a comment, then tap the parent comment at the top of the thread. A duplicate expense screen is pushed, and its < returns to the comment thread instead of Spend > Expenses. Tapping the parent comment should go back to the expense with the comment highlighted, and < should then return to Spend > Expenses.

What is the root cause of that problem?

Spend opens a one-expense report on the expense report ID. It only opens the transaction thread for self-DM and multi-expense reports (Search/index.tsx#L795-L801). That screen shows the transaction thread's comments inline, so the parent comment belongs to the transaction thread.

Tapping the parent comment calls navigateToLinkedReportAction, which reuses the screen below only on an exact ID match (ReportUtils.ts#L12696). Expense report ≠ transaction thread, so it pushes SEARCH_REPORT(transactionThread, backTo: SEARCH_REPORT) on top of the comment thread. That screen's < is a plain goBack(), which lands on the comment thread.

What changes do you think we should make in order to solve the problem?

Keep the fix in navigateToLinkedReportAction, as you suggested. Reuse the screen below when it is the report that displays the ancestor:

  • getDisplayedReportID(ancestor) equals the report below (the parent of a one-transaction thread), and
  • the report below has transactionCount === 1 (isOneTransactionReport). getDisplayedReportID decides from the loaded actions, so a multi-expense report with only one expense loaded would otherwise match. The server count prevents that, and
  • the screen below is SEARCH_REPORT. Spend > Reports and Home open a report in SEARCH_MONEY_REQUEST_REPORT / EXPENSE_REPORT (Search/index.tsx#L858), which render SearchMoneyRequestReportPage from the route's reportID and can't show a transaction thread. Those keep today's behavior instead of being pointed at the thread.
diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index 4e377a8eb2c9..e051aae10f02 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -12693,8 +12693,17 @@ function navigateToLinkedReportAction(
         const routeBelow = rhpIndex > 0 ? rhpState?.routes.at(rhpIndex - 1) : undefined;
         const routeBelowParams = routeBelow?.params as {reportID?: string} | undefined;
 
-        if (routeBelow?.key && routeBelowParams?.reportID === ancestor.report.reportID) {
-            Navigation.setParams({reportActionID: ancestor.reportAction.reportActionID}, routeBelow.key, rhpState?.key);
+        // A one-expense report shows its transaction thread's comments inline. The server's transactionCount keeps a partly loaded multi-expense report from matching.
+        // Only SEARCH_REPORT can be pointed at the thread: Spend > Reports and Home open the report in the money request report page, which can't show a thread.
+        const isAncestorShownInRouteBelow =
+            routeBelowParams?.reportID === ancestor.report.reportID ||
+            (routeBelow?.name === SCREENS.RIGHT_MODAL.SEARCH_REPORT &&
+                !!ancestor.report.reportID &&
+                routeBelowParams?.reportID === getDisplayedReportID(ancestor.report.reportID, isOffline) &&
+                isOneTransactionReport(getReport(routeBelowParams.reportID, deprecatedAllReports)));
+
+        if (routeBelow?.key && isAncestorShownInRouteBelow) {
+            Navigation.setParams({reportID: ancestor.report.reportID, reportActionID: ancestor.reportAction.reportActionID}, routeBelow.key, rhpState?.key);
             Navigation.goBack();
             return;
         }

Why the reused screen also gets the thread's reportID, not only reportActionID: with only reportActionID on the expense report route, the highlight is lost, which is what you saw when testing Melvin's first version. LinkedActionNotFoundGuard looks the action up in the route report's actions (LinkedActionNotFoundGuard.tsx#L65-L67). The comment belongs to the transaction thread, so it isn't found and once loading finishes the guard treats it as unavailable and clears reportActionID (#L105-L106, #L144-L148). Pointing the reused route's existing reportID at the thread fixes that, and still adds no new route param:

  • reportID and reportActionID are both params that route already has. The route key, its backTo, and its place in the stack stay the same, so < dismisses the RHP to Spend > Expenses.
  • The comment is found in the thread's actions, so it is scrolled to and highlighted.
  • The thread screen is the same expense view Spend already opens for multi-expense and self-DM expenses (Search/index.tsx#L799-L800). It shows the expense details, and the wide RHP receipt panel still shows because the thread's parent action is a transaction (WideRHPReceiptPanel.tsx#L75). It is not redirected back while reportActionID is set (OneTransactionThreadRedirectHandler.tsx#L86-L91).

The exact-ID case is unchanged (its reportID is already the ancestor's), and the wide-layout branch is not touched.

Branch: https://github.com/samithreddychinni/App/tree/fix/107808-reuse-one-expense-search-report
Compare diff: https://github.com/Expensify/App/compare/main...samithreddychinni:App:fix/107808-reuse-one-expense-search-report

POC video:

https://github.com/user-attachments/assets/bb508d49-ea54-4c0e-8d10-1fbbe163dcd0

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

In tests/unit/ReportUtilsNavigateToLinkedReportActionTest.ts, with the RHP stack mocked:

  1. A one-expense report below the thread, and the ancestor is its transaction thread: the route below is reused with the thread's reportID and reportActionID, the thread is popped, and nothing is pushed.
  2. A multi-expense report below (transactionCount: 2) with only one expense loaded: a new screen is pushed, as today.
  3. The one-expense report below is the SEARCH_MONEY_REQUEST_REPORT page (Spend > Reports): a new screen is pushed, as today.
  4. The route below has the ancestor's exact ID: reused and popped, as today.
  5. An unrelated report below: pushed, as today.
  6. A non-transaction child of the report below: pushed, as today.
  7. No screen below: pushed, as today.

Test 1 fails on main (it pushes a new screen instead of going back). Test 2 fails without the transactionCount check, and test 3 fails without the SEARCH_REPORT check. All 7 pass on the branch, and lint and spell check pass on the changed files.

What alternative solutions did you explore? (Optional)

  • Set only reportActionID on the expense report route: Back works, but LinkedActionNotFoundGuard can't find the thread's comment in the expense report's actions, clears the param, and the highlight is lost.
  • Go back without any param: Back works, but there is no highlight.
  • Teach the guard and pagination to read the thread's actions on the expense report route: this is the broad change Melvin's second version describes. It touches several files for something the existing reportID param already handles.
  • Change ReportHeader Back: this hides the duplicate screen instead of not pushing it.

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01cfe51584d8033bdc

samithreddychinni avatar Nov 27 '26 18:11 samithreddychinni

Proposal

What is the root cause of that problem?

Tapping the parent comment calls navigateToLinkedReportAction. In the RHP it pops back to the screen below only when that screen has the ancestor's exact report ID. Otherwise it pushes a new SEARCH_REPORT with backTo: SEARCH_REPORT, and that screen's Back is a plain goBack():

https://github.com/Expensify/App/blob/d7c37c01c1f789576fce663d34cc8255e4a55f51/src/libs/ReportUtils.ts#L12446-L12461

In this flow the IDs never match. Spend opens a one-expense report on the expense report ID. It only switches to the transaction thread for self-DM and multi-expense reports:

https://github.com/Expensify/App/blob/d7c37c01c1f789576fce663d34cc8255e4a55f51/src/components/Search/index.tsx#L787-L795

But comments typed in that combined view are written to the transaction thread (useComposerReportData.ts#L32-L33, useComposerSubmit.ts#L51-L52). So after "Reply in thread", the parent comment's report is the transaction thread, while the screen below is the expense report. The check fails, and a third screen goes on top of the thread: [expense report, comment thread, transaction thread]. Back on that third screen pops to the comment thread.

The thread header's "From …" link doesn't have this problem, because HeaderView already resolves a one-transaction parent to its expense report and drops the action ID (HeaderView.tsx#L198-L199, #L494). The ancestor row is the entry point that misses it.

This isn't caused by #104926. The guard came in with #90680, and the flow reproduces on production too.

What changes do you think we should make in order to solve the problem?

I'd fix it in navigateToLinkedReportAction, RHP branch only, because that's where the decision between "pop back" and "push" is made.

After the existing exact-ID check, add one more case: if the route below is the report that displays the ancestor, go back to it. We already have a helper for this. getDisplayedReportID returns the expense report ID for a one-transaction thread and the same ID for anything else (ReportUtils.ts#L3098-L3112):

if (routeBelow?.key && routeBelowParams?.reportID === getDisplayedReportID(ancestor.report.reportID, isOffline)) {
    Navigation.goBack();
    return;
}

There's no setParams in this branch, on purpose. The parent comment's ID belongs to the transaction thread, not to the expense report. If we set it on the expense report route, the paginated actions look for it among the expense report's actions, don't find it, and return an empty list (PaginationUtils.ts#L406-L411). That same list is what the one-expense view uses to find its transaction thread (useReportActionsPagination.ts#L66), so the expense would render empty and fire OpenReport with an action ID from another report, until LinkedActionNotFoundGuard clears the param. Going back with no param shows the expense as the user left it, and its < closes the RHP back to Spend > Expenses.

What stays the same:

  • When the transaction thread itself is below (multi-expense and self-DM flows open it directly), the exact-ID check still runs first, with setParams + goBack.
  • A multi-expense report below doesn't match, because getDisplayedReportID returns the thread's own ID there, so we still push the thread. That report doesn't show the thread's comments inline.
  • If the thread or its parent isn't in Onyx, getDisplayedReportID returns the input ID, and we fall back to today's push.
  • The wide-layout branch isn't touched.

I tested this locally. I added tests/unit/NavigateToLinkedReportActionTest.ts with the RHP stack mocked:

  • The one-expense case fails on main (navigate is called, goBack isn't) and passes with the change.
  • "Multi-expense report below", "exact ID below" and "unrelated report below" all keep today's behavior.
  • ReportUtilsTest, AncestorReportActionItemTest and the new file pass: 1781/1781. Typecheck and lint are clean on the changed files.

What alternative solutions did you explore? (Optional)

  • Link the comment on the expense report (setParams + goBack) so it gets highlighted. I rejected this because of the empty-list problem above. Linking a thread's comment from the parent report's route isn't something the linked-action pagination supports today.
  • Resolve the ancestor in AncestorReportActionItem and pass the expense report into the helper, the way HeaderView does. I rejected this because the wide-layout branch of the same helper needs the real ancestor ID for REPORT_WITH_ID and the visibility check. Swapping the report at the call site would change that path too.
  • Open the transaction thread from Spend instead of the expense report. I rejected this because Search opens the combined one-expense view on purpose, and changing it affects every Spend row, not just this flow.

oqildev avatar Nov 27 '26 18:11 oqildev