Skip to content

[$250] Expense - Approval modal does not show up, held expense is auto unheld #87223

Closed as duplicate

Description

@mitarachim

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.53-1
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://test-management.browserstack.com/projects/2219752/test-runs/TR-16381/folder/13176872/41237335/1309878949?sort=-identifier
Email or phone of affected tester (no customers): sodijdsoijsoijsoj@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. Go to workspace chat.
  3. Create an expense.
  4. Open the expense report.
  5. Click Submit.
  6. Create another expense in the same report.
  7. Open any expense.
  8. Click More > Hold.
  9. Enter reason and save it.
  10. Close the expense thread RHP.
  11. Click Approve.

Expected Result:

Approval modal will show up to confirm approval amount.

Actual Result:

Approval modal does not show up. The held expense is auto unheld.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7123326_1775535531245.14.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022053919194836242151
  • Upwork Job ID: 2053919194836242151
  • Last Price Increase: 2026-05-18
Issue OwnerCurrent Issue Owner: @marcaaron

Activity

  1. added
    Daily
    Bug
    and removed on May 11, 2026
  2. MelvinBot commented on May 11, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    The header primary "Approve" button uses useConfirmApproval which calls hasHeldExpenses(reportID) — a function that relies on a non-reactive module-level global (deprecatedReportsTransactions) populated via Onyx.connect. This global can be stale when the hold was recently applied, causing isAnyTransactionOnHold to be false at render time. The confirmation modal is skipped and approveMoneyRequest is called with full: true, which optimistically clears the hold on all held transactions — auto-unholding them without user confirmation.

    The function itself is annotated with a warning: "Use hasHeldExpensesFromTransactions instead." The other two approve paths (ApproveActionButton and useLifecycleActions) already use the reactive useTransactionsAndViolationsForReport hook and pass the result to hasHeldExpensesFromTransactions, so they correctly detect held expenses.

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

    In useConfirmApproval.ts, switch from the deprecated hasHeldExpenses(reportID) to the reactive pattern used by the other approve paths:

    1. Add useTransactionsAndViolationsForReport(reportID) to fetch transactions reactively.
    2. Replace hasHeldExpenses(moneyRequestReport?.reportID) with hasHeldExpensesFromTransactions(transactions).

    This aligns the header approve button with the existing correct implementations in ApproveActionButton and useLifecycleActions.

    Investigation details

    Three parallel approve paths exist, but only one is buggy:

    Entry point Hold check method Data source Reactive?
    useConfirmApproval.ts:32 (header button) hasHeldExpenses(reportID) deprecatedReportsTransactions global No
    ApproveActionButton.tsx:56 (report preview) hasHeldExpensesFromTransactions(transactions) useTransactionsAndViolationsForReport hook Yes
    useLifecycleActions.tsx:128 (secondary menu) hasHeldExpensesFromTransactions(transactions) useTransactionsAndViolationsForReport hook Yes

    The deprecated global deprecatedReportsTransactions is populated by an Onyx.connect callback with waitForCollectionCallback: true. Unlike useOnyx hooks, this does not trigger React re-renders when transactions change. When a hold is applied and the user navigates back and clicks Approve before this callback fires, the check misses the held expense.

    Possibly related open issues
    • Expensify/App#89429 — Held Expense with Multiple Violations Is Automatically Unheld and Approved Without Prompt
    • Expensify/App#88355 — Rejected and Held Expenses Not Handled Correctly During Approval Flow
    • Expensify/App#87971 — Approval Modal Shows Incorrect Amounts and Inconsistent State for Reports with Held Expenses

    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.

  3. added
    External
    on May 11, 2026
  4. added
    Help Wanted
    on May 11, 2026
  5. melvin-bot commented on May 11, 2026

    @melvin-bot

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

  6. changed the title [-]Expense - Approval modal does not show up, held expense is auto unheld[/-] [+][$250] Expense - Approval modal does not show up, held expense is auto unheld[/+] on May 11, 2026
  7. melvin-bot commented on May 11, 2026

    @melvin-bot
  8. aswin-s commented on May 11, 2026

    @aswin-s
    Contributor

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

    When a user holds an expense on a submitted money-request report and then clicks Approve from the report header, two things go wrong simultaneously: the approval confirmation modal never appears, and the held expense is silently un-held. The expected behavior is that clicking Approve while any transaction is on hold should open the hold-menu modal, which lets the user review and confirm what will happen to held expenses before approval proceeds.

    What is the root cause of that problem?

    The bug is in src/components/MoneyReportHeaderPrimaryAction/useConfirmApproval.ts at line 31.

    const hasViolations = hasViolationsReportUtils(moneyRequestReport?.reportID, allTransactionViolations, accountID, email ?? '');

    The line reads:

    const isAnyTransactionOnHold = hasHeldExpensesReportUtils(moneyRequestReport?.reportID);

    hasHeldExpenses in src/libs/ReportUtils.ts (lines 10841–10845) accepts an optional second argument allReportTransactions?: Transaction[]. When that argument is omitted, it falls back to getReportTransactions(iouReportID), which reads from a module-level non-reactive snapshot (deprecatedReportsTransactions). That snapshot is populated at startup and does not update when Onyx writes a hold optimistically. So immediately after the user taps Hold and then taps Approve, the snapshot still reflects the pre-hold state — isAnyTransactionOnHold is false.

    Because isAnyTransactionOnHold is false, confirmApproval skips the openHoldMenu branch and falls through to approveMoneyRequest({..., full: true}). Inside approveMoneyRequest, the held status is read via a separate, live Onyx path, so it correctly sees the hold — and wipes the hold reason as part of the full-approval flow. That produces both symptoms: no modal, and the hold disappears.

    The correct pattern already exists in the codebase. src/components/MoneyReportHeaderModals.tsx (lines 41–50) uses useTransactionsAndViolationsForReport — a fully reactive hook that subscribes to Onyx — and passes its transactions map to the hold-check utilities. useConfirmApproval needs to do the same.

    Note: hasHeldExpenses carries an in-source @warning directing callers to prefer hasHeldExpensesFromTransactions (src/libs/ReportUtils.ts, lines 10850–10852), which takes a required Transaction[] and has no stale-snapshot fallback. The fix targets that preferred API directly.

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

    File: src/components/MoneyReportHeaderPrimaryAction/useConfirmApproval.ts

    1. Import useTransactionsAndViolationsForReport from @hooks/useTransactionsAndViolationsForReport.
    2. Import hasHeldExpensesFromTransactions (the preferred, snapshot-free variant) from @libs/ReportUtils alongside the existing hasHeldExpenses import.
    3. Call the hook and derive a Transaction[] from the reactive map it returns. Guard against the case where the hook returns no transactions (e.g. the report has not loaded yet) by defaulting to an empty array — hasHeldExpensesFromTransactions([]) correctly returns false, which is safe: if there are no transactions loaded, there is nothing to hold-check against and approval proceeds normally.
    4. Replace the stale-snapshot call with the reactive one.
    // 1. New import (add alongside existing hook imports)
    import useTransactionsAndViolationsForReport from '@hooks/useTransactionsAndViolationsForReport';
    
    // 2. Updated ReportUtils import — add hasHeldExpensesFromTransactions
    import {
        ...,
        hasHeldExpensesFromTransactions as hasHeldExpensesReportUtilsFromTransactions,
    } from '@libs/ReportUtils';

    Inside the hook body, after the existing useOnyx calls:

    // Before (line 31) — reads from stale non-reactive snapshot:
    // const isAnyTransactionOnHold = hasHeldExpensesReportUtils(moneyRequestReport?.reportID);
    
    // After — reactive, always reflects current Onyx state:
    const {transactions: transactionsForReport} = useTransactionsAndViolationsForReport(moneyRequestReport?.reportID);
    const transactionsArray = Object.values(transactionsForReport ?? {});
    const isAnyTransactionOnHold = hasHeldExpensesReportUtilsFromTransactions(transactionsArray);

    useTransactionsAndViolationsForReport returns {transactions, violations} where transactions is a Record<string, Transaction> keyed by the full Onyx key. Object.values(transactionsForReport ?? {}) converts it to Transaction[] safely — when the report has no transactions or has not loaded yet, it produces [] and hasHeldExpensesFromTransactions returns false, which is the correct safe default (no hold check fires for an empty report).

    No other files need changes. The rest of confirmApproval — the openHoldMenu call, the approveMoneyRequest call, and the delegate-access guard — is correct as written.

    What alternative solutions did you explore?

    Pass reportID + the optional second argument to the existing hasHeldExpenses.
    hasHeldExpenses does accept allReportTransactions?: Transaction[] as a second argument, so it could be called as hasHeldExpenses(reportID, transactionsArray). This works, but hasHeldExpenses carries an explicit @warning in its JSDoc saying callers should use hasHeldExpensesFromTransactions instead. Calling the preferred function directly is cleaner and removes any ambiguity about which code path executes.

    Subscribe to ONYXKEYS.COLLECTION.TRANSACTION directly via useOnyx.
    Adding a useOnyx call for the full transaction collection would give reactive data, but it would subscribe to all transactions across all reports — a much broader Onyx subscription than needed. useTransactionsAndViolationsForReport already scopes the subscription to the specific report, so it is strictly preferable.

    Read transactions inside confirmApproval at call time.
    Calling getReportTransactions inside the confirmApproval callback (at click time rather than at render time) would pick up the latest snapshot value. However, the snapshot is module-level and not guaranteed to be flushed by the time the click handler fires; this is the same underlying fragility. React state derived from a hook is the idiomatic and reliable solution.

  9. 12 remaining items

  10. nguyenlnp commented on May 21, 2026

    @nguyenlnp

    Proposal

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

    When a user holds an expense on a submitted money-request report and then clicks Approve from the report header, the approval confirmation modal does not appear and the held expense is silently un-held. The expected behavior is that the hold menu modal appears, letting the user confirm what happens to held expenses before proceeding.

    What is the root cause of that problem?

    The primary root cause — useConfirmApproval.ts calling the deprecated hasHeldExpenses(reportID) which reads from the non-reactive deprecatedReportsTransactions module-level global — has already been fixed on main. The hook now uses useTransactionsAndViolationsForReport + hasHeldExpensesFromTransactions, which is reactive and correctly triggers re-renders when hold state changes. ✅

    However, there is a remaining stale-data path in approveMoneyRequest (src/libs/actions/IOU/ReportWorkflow.ts) that has not been addressed:

    At line 377, approveMoneyRequest calls:

    const reportTransactions = getReportTransactions(expenseReport.reportID);

    and at line 379:

    const hasHeldExpenses = hasHeldExpensesReportUtils(reportTransactions);

    The import at line 35 is:

    import {hasHeldExpenses as hasHeldExpensesReportUtils, …} from @libs/ReportUtils;

    While hasHeldExpenses and hasHeldExpensesFromTransactions have identical implementations when called with a Transaction[] argument (both just call .some(t => isOnHold(t)) on the array), hasHeldExpenses carries an explicit @warning to prefer the named variant. More importantly, getReportTransactions on line 377 resolves through the same deprecatedReportsTransactions global, meaning reportTransactions itself may be stale.

    When useConfirmApproval now correctly opens the hold menu and the user confirms, approveMoneyRequest is called with full: true. Inside that function, the hasHeldExpenses determination at line 379 comes from the stale global. If the global is stale (which is less likely in this specific flow since the user just interacted with the modal, but possible in edge cases like rapid network changes), the hold-clearing logic at lines 617–629 would be skipped. Conversely, if the global IS current, it works — but this is by accident, not by design.

    The same pattern exists in two sibling action functions:

    • submitMoneyRequest (line 138): const reportTransactions = iouTransactions ?? getReportTransactions(iouReport?.reportID);
    • payMoneyRequest (line 293): getReportTransactions(iouReport?.reportID)

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

    Change 1 — src/libs/actions/IOU/ReportWorkflow.ts line 35:

    Replace the deprecated import with the preferred variant:

    -import {hasHeldExpenses as hasHeldExpensesReportUtils, …} from @libs/ReportUtils;
    +import {hasHeldExpensesFromTransactions as hasHeldExpensesReportUtils, …} from @libs/ReportUtils;

    This is a safe drop-in replacement because both functions accept Transaction[] and have identical behavior when called with a populated array. The only reason hasHeldExpenses exists separately is its deprecated overload that accepts a reportID string and reads from the global — but that overload is never triggered when a populated array is passed. Using hasHeldExpensesFromTransactions follows the explicit @warning in the codebase and makes the intent clear: we are intentionally passing pre-fetched transaction data, not relying on a global cache.

    Change 2 — Consistency: apply the same swap in sibling functions.

    The same import swap should be applied wherever hasHeldExpenses is imported in ReportWorkflow.ts for the same pattern (calling with getReportTransactions result). This ensures all three action functions (approveMoneyRequest, submitMoneyRequest, payMoneyRequest) consistently use the non-deprecated variant.

    Change 3 (already on main) — useConfirmApproval.ts:

    The switch to useTransactionsAndViolationsForReport + hasHeldExpensesFromTransactions is already in place on the main branch. This resolved the modal-not-showing symptom. No further changes needed here.

    Overall impact: After these changes, the only remaining callers of the deprecated hasHeldExpenses (the string-ID overload) will be in ReportUtils.ts internal functions like hasOptimisticHeldExpense (line 10872) and hasReportHeldExpense (line 10898) — these are utility functions that intentionally read from the global and are not involved in the approval flow. The deprecated overload path will no longer be reachable from any approval or hold-flow call site.

    What alternative solutions did you explore? (Optional)

    • Pass reactive transactions from useConfirmApproval into approveMoneyRequest via an iouTransactions parameter. approveMoneyRequest already has an optional iouTransactions parameter used by submitMoneyRequest. Extending it would ensure the caller's reactive data flows through, but it requires updating all callers and the function signature — the import swap achieves the same consistency goal with minimal diff size.

    • Remove getReportTransactions calls inside approveMoneyRequest and require callers to pass transactions. This is the cleanest long-term fix but is a larger refactor. The import swap is the minimal safe change that eliminates the deprecated function from the approval flow without breaking existing callers.

    • Add a useOnyx subscription for ONYXKEYS.COLLECTION.TRANSACTION with a selector inside useConfirmApproval (as proposed by @Hossiy21). This is a valid alternative approach for the useConfirmApproval path, but it does not address the ReportWorkflow.ts action-function path, which cannot use hooks. The reactive-hook fix is already on main, and the import swap in ReportWorkflow.ts is the complementary action-function fix.

  11. melvin-bot commented on May 21, 2026

    @melvin-bot

    📣 @nguyenlnp! 📣
    Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
    Please follow these steps:

    1. Make sure you've read and understood the contributing guidelines.
    2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
    3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
    4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
      Screen Shot 2022-11-16 at 4 42 54 PM
      Format:
    Contributor details
    Your Expensify account email: <REPLACE EMAIL HERE>
    Upwork Profile Link: <REPLACE LINK HERE>
    
  12. nguyenlnp commented on May 21, 2026

    @nguyenlnp

    Contributor details
    Your Expensify account email: contact@nguyenlnp.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~01a8d28742cf532153

  13. melvin-bot commented on May 21, 2026

    @melvin-bot

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

  14. melvin-bot commented on May 22, 2026

    @melvin-bot

    @ChavdaSachin 10 days overdue. Is anyone even seeing these? Hello?

  15. ChavdaSachin commented on May 25, 2026

    @ChavdaSachin
    Contributor

    @MelvinBot, please create a draft from your proposal, and also summarize and review all the available proposals.

  16. MelvinBot commented on May 25, 2026

    @MelvinBot
    Contributor

    Draft PR Status

    The fix from my proposal has already been merged to main. The file useConfirmApproval.ts now uses the reactive useTransactionsAndViolationsForReport hook and hasHeldExpensesFromTransactions, which is exactly what my proposal recommended. There is no draft PR to create — the primary fix is already shipped.


    Proposal Summary & Review

    All proposals except one identify the same root cause and recommend the same fix. Here's a comparison:

    # Author Root Cause Proposed Fix Status
    1 MelvinBot useConfirmApproval uses deprecated non-reactive hasHeldExpenses(reportID) Switch to useTransactionsAndViolationsForReport + hasHeldExpensesFromTransactions ✅ Already merged
    2 aswin-s Same as above Same fix + mentions edge-case guards ✅ Correct, already merged
    3 wildan-m Same as above Same fix (includes compare branch) ✅ Correct, already merged
    4 Hossiy21 Same as above Same fix ✅ Correct, already merged
    5 Abdulloh0109 Same as above Same fix ✅ Correct, already merged
    6 nguyenlnp Acknowledges primary fix is merged; flags remaining stale paths in ReportWorkflow.ts Replace getReportTransactions + hasHeldExpenses calls in action functions ⚠️ Different scope — see below

    Detailed Review

    Proposals 1–5 (MelvinBot, aswin-s, wildan-m, Hossiy21, Abdulloh0109): All correctly identified the non-reactive deprecatedReportsTransactions global as the root cause and proposed the same reactive hook fix. The fix is already on main. These proposals are all substantively identical. wildan-m provided a compare branch which is a nice touch, and aswin-s mentioned additional edge-case guards, but the core fix is the same across all five.

    Proposal 6 (nguyenlnp): This is the only proposal that acknowledges the primary fix is already merged and instead focuses on remaining stale-data paths in src/libs/actions/IOU/ReportWorkflow.ts. Specifically, approveMoneyRequest (line 381), submitMoneyRequest (line 138), and payMoneyRequest (line 297) still call getReportTransactions() which reads from the same deprecated global. However, these are action functions (not React hooks), so they run imperatively at call time rather than at render time. The staleness risk is lower here because the global is typically up-to-date by the time a user clicks through a modal confirmation. This proposal addresses a valid code-quality concern (using deprecated APIs) but is less clearly a fix for the reported bug.

    Recommendation

    Since the primary fix is already merged, the issue may be ready to close pending QA verification. If there's interest in the cleanup nguyenlnp identified in ReportWorkflow.ts, that could be tracked as a separate follow-up task.


    Next Steps: Reply with @MelvinBot <your feedback> if you need anything else.

  17. ChavdaSachin commented on May 25, 2026

    @ChavdaSachin
    Contributor

    🎀 👀 🎀 C+ reviewed

    Issue no longer reproducible; already fixed elsewhere.
    please close this.

  18. melvin-bot commented on May 25, 2026

    @melvin-bot

    Triggered auto assignment to @marcaaron, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

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

Metadata

Metadata

Labels

BugDailyExternalHelp Wanted

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions