Skip to content

Fix merge expense transaction thread navigation - #96633

Open
marufsharifi wants to merge 15 commits into
Expensify:mainfrom
marufsharifi:fix/merge-expense-transaction-thread-navigation
Open

Fix merge expense transaction thread navigation#96633
marufsharifi wants to merge 15 commits into
Expensify:mainfrom
marufsharifi:fix/merge-expense-transaction-thread-navigation

Conversation

@marufsharifi

@marufsharifi marufsharifi commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Merge expense now follows the same destination behavior across individual and bulk merge flows.

Before this update, merging expenses from search/spend could open the wrong place or leave the RHP loading, especially when the target workspace expense did not already have a transaction thread and the destination was an unreported/self-DM expense.

Now, the app creates the missing optimistic transaction thread when needed, carries that thread through confirmation, and attaches offline optimistic merge data to the correct destination report. This makes post-merge navigation consistent and predictable for workspace, self-DM, split, and offline merge cases.

Fixed Issues

$ #83257
PROPOSAL:

Tests

Flow 1: Workspace expense with self-DM expense

  1. Create an expense in self DM.
  2. Create an expense in workspace chat.
  3. Go to Spend > Expenses.
  4. Select the workspace expense via the checkbox.
  5. Click the dropdown button > Merge.
  6. Select self DM expense > Continue.
  7. Select the second option in each section > Next > Merge expenses.
  8. Verify the transaction thread opens after merging expenses via the bulk option.
  9. Verify the app does not open the self-DM “Your space” page.

Flow 2: Workspace manual expense with split expense

  1. Go to a workspace chat.
  2. Create an expense split.
  3. Create a manual expense.
  4. Navigate to Spend > Expenses.
  5. Select the manual expense created in Step 3 using the checkbox, then click Merge.
  6. In the merge flow, choose the Split Expense option and complete the merge.
  7. Verify that the transaction thread opens automatically after the expenses are merged using the bulk merge option.

Flow 3: Offline workspace expense with self-DM expense

  1. Create an expense in self DM.
  2. Create an expense in workspace chat.
  3. Go to Spend > Expenses.
  4. Turn off internet connection.
  5. Select the workspace expense via the checkbox.
  6. Click the dropdown button > Merge.
  7. Select self DM expense > Continue.
  8. Select the second option in each section > Next > Merge expenses.
  9. Verify the transaction thread opens after merging expenses via the bulk option.
  10. Verify the RHP does not load infinitely.
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native

Flow:1

flow01.mov

Flow:2

flow02.mov

Flow:3

flow03.mov
Android: mWeb Chrome

Flow:1

flow1.mp4

Flow:2

flow2.mp4

Flow:3

flow3.mp4
iOS: Native

Flow:1

flow001.mov

Flow:2

flow002.mov

Flow:3

flow003.mov
iOS: mWeb Safari

Flow:1

flow0001.mov

Flow:2

flow0002.mov

Flow:3

Screen.Recording.2026-07-21.at.8.17.39.PM.mov
MacOS: Chrome / Safari

Flow:1

flow1.mov

Flow:2

flow2.mov

Flow:3

flow3.mov

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Coverage Δ
src/hooks/useSearchBulkActions.ts 59.73% <ø> (ø)
src/libs/actions/MergeTransaction.ts 68.26% <100.00%> (+2.10%) ⬆️
src/libs/actions/Report/index.ts 71.64% <100.00%> (+0.02%) ⬆️
...pages/TransactionMerge/DynamicConfirmationPage.tsx 0.00% <0.00%> (ø)
... and 8 files with indirect coverage changes

@marufsharifi
marufsharifi marked this pull request as ready for review July 21, 2026 16:01
@marufsharifi
marufsharifi requested review from a team as code owners July 21, 2026 16:01
@melvin-bot
melvin-bot Bot requested review from joekaufmanexpensify and rojiphil and removed request for a team July 21, 2026 16:01
@melvin-bot

melvin-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

@rojiphil 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 removed request for a team and joekaufmanexpensify July 21, 2026 16:01
@marufsharifi

Copy link
Copy Markdown
Contributor Author

@rojiphil, could you please take a look at this. thanks.

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@rojiphil, Gentle bump. thanks.

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@rojiphil, Friendly bump. thanks.

@rojiphil

Copy link
Copy Markdown
Contributor

@marufsharifi Picking this up today

@rojiphil

Copy link
Copy Markdown
Contributor

Thanks @marufsharifi for the update. The core approach used here looks like a good improvement over the original PR. The offline issue also seems to have been fixed. Will take a closer look at the code sometime today.

96633-web-chrome-001.mp4

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@rojiphil, Quick bump. thanks.

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@rojiphil, quick bump. thanks.

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@rojiphil, Friendly bump. thanks.

@marufsharifi

Copy link
Copy Markdown
Contributor Author

bumped in slack.

@rojiphil

rojiphil commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

@codex review

@rojiphil

rojiphil commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d066c8dfb4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/pages/TransactionMerge/DynamicConfirmationPage.tsx Outdated
Comment thread src/libs/actions/MergeTransaction.ts
@MelvinBot

Copy link
Copy Markdown
Contributor

Review — looks solid ✅

Approach is sound and matches the reported bug (#83257). The fix has three coordinated parts, all of which check out:

  1. Bulk flow now passes policies into target/source selectionuseSearchBulkActions.ts:2074 forwards transactionPolicies to setupMergeTransactionDataAndNavigate, so selectTargetAndSourceTransactionsForMerge picks the same target the individual flow does. This is the root cause of "self-DM opens instead of the thread."
  2. Missing thread is seeded on confirmDynamicConfirmationPage.tsx:100-119 creates the optimistic transaction thread when the target never had one, and navigation lands on it.
  3. Optimistic merge data attaches to the real self-DM (not report "0") via optimisticDestinationReportID, and hasOptimisticReportActions clears the initial-loading state so the RHP doesn't spin forever (Report/index.ts:1590-1591).

Verification

  • All CI checks pass (test ×8, typecheck, ESLint, Oxfmt, React Compiler, Storybook). Coverage on the two touched action files went up.
  • Manually re-ran the bulk-merge flow on web (Flow 1): the merged transaction thread opened correctly and the self-DM "Your space" page did not open; RHP loaded fully with no infinite spinner.

A couple of non-blocking things worth a look:

Observations / questions
  • hasOptimisticReportActions=false path is safe — the new Report/index.ts:1590 writes hasOnceLoadedReportActions: undefined for existing callers, which Onyx MERGE drops, so no behavior change for the many other openReport callers. Just calling out that this relies on Onyx dropping undefined on merge — fine, but a bit implicit.

  • Extra OpenReport command on confirm. When the target has no thread, createTransactionThreadReport runs inside the click handler and fires its own OpenReport (via openReport) in addition to MergeTransaction. Worth confirming this double-command is intended and that the backend reconciles the separately-seeded thread with the merged expense in all cases (the client-generated thread reportID is sent via OpenReport, but is not in the MergeTransaction params — MergeTransaction.ts:432-459). Online it worked cleanly in my test; the offline hand-off is the interesting case.

  • Two self-DM resolution paths. The page computes the destination with findSelfDMReportID() (DynamicConfirmationPage.tsx:92) while mergeTransactionRequest uses the useSelfDMReport() value (selfDMReport?.reportID). They should agree in practice, but if the self-DM report is missing/filtered the action falls back to report "0" while createTransactionThreadReport builds an optimistic self-DM instead — a minor inconsistency in the (rare) missing-self-DM edge. Probably not worth handling, just flagging.

Nice test coverage on the new branches (unreported→self-DM attach, and the "IOU action has no childReportID" path). No blocking concerns from me on the code.


This is an automated review. Reply with @MelvinBot <feedback> to refine.

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@rojiphil, addressed feedback, all yours. Thanks!

@rojiphil

rojiphil commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@marufsharifi A duplicate expense is created in self DM when merged with an unreported expense. Please have a look. Thanks

96633-issue-004.mp4

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@marufsharifi A duplicate expense is created in self DM when merged with an unreported expense. Please have a look. Thanks

96633-issue-004.mp4

@rojiphil addressed this case too. could you check once again, thanks

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@rojiphil, Gentle bump. thanks.

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@rojiphil, Friendly bump. thanks.

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.

3 participants