Skip to content

[Due for payment 2026-03-31] Expense - Tax rate section is missing when merging expenses when Reports tab is opened #85175

Closed

Description

@jponikarchuk

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.3.37-0
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #83587
Email or phone of affected tester (no customers): jsoidjsojniodnjiojs@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.2 / Chrome
App Component: Money Requests

Action Performed:

  1. Go to staging.new.expensify.com
  2. Create a new account.
  3. Create two workspaces and enable Taxes for both workspaces.
  4. Go to Reports tab (IMPORTANT).
  5. Go to Inbox.
  6. Go to workspace chat A.
  7. Create an expense with 0% tax rate.
  8. Go to workspace chat B.
  9. Create an expense with 5% tax rate.
  10. Open the expense (can be any from Step 7 or 9).
  11. Click More > Merge.
  12. Select the other expense > Continue.

Expected Result:

Tax rate section will be shown.

Actual Result:

Tax rate section is missing when merging expenses when Reports tab is opened.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

Video.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @dominictb

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Mar 13, 2026
  2. melvin-bot commented on Mar 13, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #83587

  3. melvin-bot commented on Mar 13, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  4. github-actions commented on Mar 13, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  5. OSBotify commented on Mar 13, 2026

    @OSBotify
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: #83587 - "[Merge] Merge tax rates v2" by @dominictb (High confidence)
    Related Issues: None

    Recommendation: REVERT

    The PR introduced a regression where tax rate section is missing when merging expenses outside of Search context (e.g., when navigating from Reports tab). This is a clear regression from the new tax merge functionality and reverting will restore the previous working state while the fix is developed.

    Labels: No label changes made (keeping DeployBlockerCash as this is a frontend bug)

    📋 Detailed Analysis

    Evidence

    The bug occurs specifically when:

    1. User navigates from Reports tab (not Search tab)
    2. Creates expenses with tax rates in workspace chats
    3. Attempts to merge those expenses

    The tax rate section appears when merging from Search tab but is missing when merging from Reports tab.

    Root Cause

    The issue is in the interaction between useMergeTransactions hook and SearchContext:

    1. Line 78 in src/hooks/useMergeTransactions.ts:

      if (currentSearchHash && currentSearchResults?.data) {

      This condition checks if the user is on a search page before fetching policy data from search results.

    2. When NOT on Search tab:

      • currentSearchHash is -1 (default value from SearchContext line 111)
      • The condition evaluates to false (since -1 is falsy in JavaScript)
      • Policy data (targetTransactionPolicy and sourceTransactionPolicy) remains undefined
    3. Line 232 in src/libs/MergeTransactionUtils.ts:

      if (field === 'taxValue' && (!targetTransactionPolicy?.tax?.trackingEnabled || !sourceTransactionPolicy?.tax?.trackingEnabled)) {
          continue;
      }

      When policies are undefined, the expression undefined?.tax?.trackingEnabled evaluates to undefined (falsy), causing the entire tax field to be skipped.

    4. Result: Tax rate section never appears in the merge UI when navigating from Reports tab.

    Verification

    Files affected by the bug:

    • src/hooks/useMergeTransactions.ts (lines 78-84) - Policy data not loaded outside search
    • src/libs/MergeTransactionUtils.ts (line 232) - Tax field skipped when policies undefined

    Confirmed PR modifies these files:

    • ✅ src/hooks/useMergeTransactions.ts - Added policy loading logic
    • ✅ src/libs/MergeTransactionUtils.ts - Added tax merge logic with policy check

    Timeline alignment:

    • PR merged: 2026-03-12
    • Bug reported: 2026-03-13 (version 9.3.37-0)
    • Bug is staging-only (new feature doesn't exist in prod)

    The bug is a direct result of PR #83587's new policy-dependent tax merge logic not accounting for non-search navigation contexts.

  6. self-assigned this
    on Mar 13, 2026
  7. MelvinBot commented on Mar 13, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When merging two expenses (from different workspaces with taxes enabled), the tax rate section is missing from the merge UI — but only when the user has navigated to the Reports tab before initiating the merge.

    What is the root cause of that problem?

    The root cause is that visiting the Reports tab causes stale search snapshot data to persist via usePreviousDefined, and the merge flow then shallow-merges that partial snapshot policy data over the full Onyx policy, destroying the tax configuration.

    The chain of causation:

    1. Search context persists after leaving the tab — SearchContext (src/components/Search/SearchContext.tsx:98) uses usePreviousDefined(queryParam) to preserve the last search query. When the user navigates away from the Reports tab, queryParam becomes undefined, but usePreviousDefined holds onto the Reports tab query. This keeps currentSearchHash set to the Reports tab hash and currentSearchResults pointing to the Reports tab snapshot (loaded via useOnyx at line 116).

    2. Merge flow unconditionally merges snapshot data — In useMergeTransactions (src/hooks/useMergeTransactions.ts:78-84), the guard currentSearchHash && currentSearchResults?.data passes even when the user is no longer on the Search screen, because both values persist from the Reports tab visit.

    3. Shallow spread overwrites nested policy data — mergePolicyWithSearchSnapshot (src/hooks/useMergeTransactions.ts:25-38) does {...onyxPolicy, ...snapshotPolicy}. Search snapshots are known to contain partial policy data (confirmed by a comment at src/components/SelectionListWithSections/Search/TransactionListItem.tsx:81: "Fetch policy categories directly from Onyx since they are not included in the search snapshot"). If the snapshot policy includes a tax key with incomplete data (e.g., tax: {} or tax without trackingEnabled), the shallow spread replaces the full Onyx tax object, losing trackingEnabled: true.

    4. Tax section is gated on policy data — At src/libs/MergeTransactionUtils.ts:232, the condition !targetTransactionPolicy?.tax?.trackingEnabled || !sourceTransactionPolicy?.tax?.trackingEnabled evaluates to true when the policy's tax.trackingEnabled is missing/falsy, causing the entire taxValue field to be skipped with continue. The tax rate section never appears in the merge UI.

    Why it only happens after visiting the Reports tab: Without visiting the Reports tab, currentSearchResults is undefined (no search snapshot fetched), so the guard at line 78 fails and mergePolicyWithSearchSnapshot is never called. The full Onyx policy (with tax.trackingEnabled: true) is used directly, and the tax section renders correctly.

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

    Fix mergePolicyWithSearchSnapshot in src/hooks/useMergeTransactions.ts to not overwrite existing Onyx policy data with partial snapshot data. The snapshot should only be used as a fallback when Onyx data is missing:

    // Change from:
    return { ...onyxPolicy, ...snapshotPolicy };
    
    // Change to:
    return onyxPolicy ?? snapshotPolicy;
    

    This preserves the intent of using snapshot data when the Onyx policy is unavailable (e.g., during search-initiated merge), while preventing partial snapshot data from overwriting the complete Onyx policy.

    What alternative solutions did you explore? (Optional)

    1. Deep merge for the tax field specifically — e.g., return { ...onyxPolicy, ...snapshotPolicy, tax: { ...onyxPolicy?.tax, ...snapshotPolicy?.tax } }. More targeted but introduces complexity and doesn't prevent similar issues with other nested policy fields in the future.

    2. Only apply snapshot merge when on the Search screen — Add a check like focusedScreenName === SCREENS.SEARCH.ROOT to the guard condition. This would work but would also break the snapshot fallback for merge flows initiated from within search results.

    3. Clear currentSearchHash when leaving the Search screen — Would require changing the usePreviousDefined behavior, which could break other search-dependent features that rely on the preserved query (e.g., returning to the last search results).

    The recommended fix (using ?? instead of spread) is the simplest and safest approach since the comment on line 24 states "Both Onyx and snapshot data can be stale, merging them to maintain freshness", but in practice, when both exist, the Onyx policy is the more complete data source and should take precedence.


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  8. dominictb commented on Mar 13, 2026

    @dominictb
    Contributor

    Culprit is here:

    return currentSearchResults?.data[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? onyxTransaction;

    We're prioritizing snapshot data over onyx data for transaction and snapshot data might not always include taxValue.

    @youssef-lr @hoangzinh Do you remember why you added that in the Phase 2 PR? Should we only use snapshot data if we're on search? Should we merge snapshot and onyx like what we did with policies here?

  9. hoangzinh commented on Mar 13, 2026

    @hoangzinh
    Contributor

    Should we only use snapshot data if we're on search?

    It was YES that time because we're on the search page.

  10. 12 remaining items

  11. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Mar 24, 2026
  12. changed the title [-]Expense - Tax rate section is missing when merging expenses when Reports tab is opened[/-] [+][Due for payment 2026-03-31] Expense - Tax rate section is missing when merging expenses when Reports tab is opened[/+] on Mar 24, 2026
  13. melvin-bot commented on Mar 24, 2026

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  14. melvin-bot commented on Mar 24, 2026

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.3.42-3 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2026-03-31. 🎊

    For reference, here are some details about the assignees on this issue:

    • @dominictb does not require payment (Contractor)
  15. melvin-bot commented on Mar 24, 2026

    @melvin-bot

    @youssef-lr @dominictb The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  16. melvin-bot commented on Mar 24, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  17. dominictb commented on Mar 24, 2026

    @dominictb
    Contributor

    Fixed. This will be paid centrally in merge project

  18. removed
    Awaiting PaymentAuto-added when associated PR is deployed to production
    on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.EngineeringMelvin TriageAutomatic AI Analysis of an issueWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions