Skip to content

[$250] Expense - Duplicated expense does not redirect to report table view #94427

Closed

Description

@applause-bot

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.4.18-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: #89585
Email or phone of affected tester (no customers): n/a
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: Mac 15.4.1 Safari, Chrome, iPhone 13 iOS 26.5
App Component: Chat Report View

Action Performed:

  1. Go to https://staging.new.expensify.com
  2. Go to a workspace chat
  3. Create a report with more than one transaction
  4. Navigate to Spend → Expenses.
  5. Open a single expense whose underlying report has more than one transaction.
  6. Tap More → Duplicate expense.

Expected Result:

The view switches to the report's table; the duplicate row shows the highlight; RHP is super-wide.

Actual Result:

Duplicated expense does not redirect to report table view and stays on expense preview page

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7189260_1782271373569.Recording__2459.mp4

View all open jobs on GitHub

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

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @abzokhattab

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jun 24, 2026
  2. applause-bot commented on Jun 24, 2026

    @applause-bot
    Author

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

  3. MelvinBot commented on Jun 24, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    This is Scenario 3 of PR #89585 (merged 2026-06-23). That PR only touched RHP width and highlight logic — it made zero navigation changes — so it never actually addressed the "redirect to report table view" half of this scenario. The redirect is genuinely missing.

    The view only flips chat→table when the RHP screen is mounted on the parent money‑request report via the table-capable SearchMoneyRequestReportPage (the EXPENSE_REPORT / SEARCH_MONEY_REQUEST_REPORT routes), where shouldDisplayReportTableView(report, transactions) becomes true once the report has >1 transaction.

    But from Spend → Expenses, opening a single expense whose underlying report has >1 transaction resolves the target to the transaction‑thread childReportID and navigates to ROUTES.SEARCH_REPORT (Search/index.tsx:540-548). That route renders ReportScreen, not the table page, and isReportTransactionThread is permanently true for a thread — so the table view can never appear, no matter how many transactions the parent gains.

    When you then tap Duplicate expense, the handler simply calls duplicateTransaction([transaction]) with no navigation (MoneyRequestHeaderSecondaryActions.tsx:410-411; Duplicate.ts has no navigation at all). The duplicate row lands in the parent report's table — a screen the user is not on — so the RHP stays on the expense preview. Result: stays on the expense preview page.

    Why Scenario 1 (single‑tx report) does work: there, the expense opens on the parent report, so duplicating bumps the displayed report's transactions.length 1→2 and the flip happens automatically. Scenario 3 fails precisely because the displayed report is a thread, not the parent — a count change can't trigger the flip.

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

    Add an explicit post‑duplicate redirect to the table-capable parent‑report route. In the DUPLICATE action's onSelected (MoneyRequestHeaderSecondaryActions.tsx:410-411), after duplicateTransaction([transaction]), when the underlying parent report will have >1 transaction, navigate to the parent report's table route — ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID: parentReport.reportID}) (the route Search already uses for multi‑tx reports, which mounts SearchMoneyRequestReportPage → MoneyRequestReportView). parentReport is already available in that component. This mirrors the chat preview path, which opens the parent iouReportID on EXPENSE_REPORT_RHP and is why the flip works from chat.

    What alternative solutions did you explore? (Optional)

    Make the table-vs-preview decision follow a transaction thread up to its parent (so a thread route can render the table once the parent goes multi-tx). This is more invasive — it changes MoneyRequestReportView/SearchMoneyRequestReportPage to resolve the parent rather than the route's literal reportID — and risks regressing the intended single-expense preview behavior. The explicit redirect is the smaller, more targeted fix.

    Investigation details & evidence

    Confidence: High — two independent investigations agree, with file:line evidence. The flip is gated on the displayed report being the parent (not a thread); from Spend→Expenses the displayed report is the thread and no navigation fires, so the gate is never satisfied.

    Note: No related duplicate issues were found in a quick open-issue scan. This is a fresh QA failure of PR #89585's Scenario 3.


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

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Jun 24, 2026
  5. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jun 24, 2026
  6. ahmdshrif commented on Jun 24, 2026

    @ahmdshrif
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2026-06-24 08:13:36 UTC.

    Proposal

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

    When you open a single expense from Spend → Expenses whose underlying report has more than one transaction and tap More → Duplicate expense, the RHP stays on the single‑expense preview instead of flipping to the report's table view (with the duplicate row highlighted and a super‑wide RHP). Scenarios where the source report has only one transaction (PR #89585 scenarios 1 & 2) work; this multi‑transaction‑source path (scenario 3) does not. Reproducible in production, so this is a pre‑existing gap, not a regression introduced by #89585.

    What is the root cause of that problem?

    The "flip to table" is driven only by the route report's own visible‑transaction count. In scenario 3 that route report is a single‑transaction thread report, and the duplicate never adds a transaction to it, so the gate can never become true.

    1. Opening an expense from the Expenses list resolves the destination reportID. When the source is not a one‑transaction report, it is reassigned from the parent report to the IOU action's childReportID — the transaction thread report — which holds exactly one expense:
      let reportID = transactionItem.reportID ?? reportActionItem.reportID;
      if (isTransactionItem && transactionItem?.reportAction?.childReportID) {
      const isFromSelfDM = transactionItem.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
      const isFromOneTransactionReport = isOneTransactionReport(transactionItem.report);
      if (isFromSelfDM || !isFromOneTransactionReport) {
      reportID = transactionItem?.reportAction?.childReportID;
      }
      }
    2. That thread report is marked as a single expense and opened as a plain SEARCH_REPORT (wide, single‑expense RHP) — not as a multi‑transaction report:
      markReportIDAsExpense(reportID);
      if (isTransactionItem && transactionPreviewData) {
      setOptimisticDataForTransactionThreadPreview(transactionItem, transactionPreviewData, transactionItem?.reportAction?.childReportID);
      }
      const route = ROUTES.SEARCH_REPORT.getRoute({reportID, backTo});
      (contrast the report‑group branch, which calls markReportIDAsMultiTransactionExpense and routes to SEARCH_MONEY_REQUEST_REPORT:
      markReportIDAsMultiTransactionExpense(reportID);
      } else {
      unmarkReportIDAsMultiTransactionExpense(reportID);
      }
      // Persist the current search context so prev/next navigation arrows
      // in the report RHP can reference the correct result set.
      saveLastSearchParams({
      queryJSON,
      offset,
      searchKey: currentSearchKey,
      hasMoreResults: !!searchResults?.search?.hasMoreResults,
      allowPostSearchRecount: true,
      });
      const route = ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID, backTo});
      ).
    3. The page that renders the RHP decides table‑vs‑single purely from the route report's transactions: shouldShowSuperWideRHP = visibleTransactions.length > 1:
      const shouldShowSuperWideRHP = visibleTransactions.length > 1;
      useShowSuperWideRHPVersion(shouldShowSuperWideRHP);
    4. Duplicating builds the new expense on a freshly generated IOU report (optimisticIOUReportID = generateReportID()) in the active‑policy expense chat (targetReport: activePolicyExpenseChat) — i.e. not in the thread report being viewed — and performs no navigation and no markReportIDAsMultiTransactionExpense:
      const duplicateExpenseTransaction = (transactionList: OnyxTypes.Transaction[]) => {
      if (!transactionList.length) {
      return;
      }
      const optimisticChatReportID = generateReportID();
      const optimisticIOUReportID = generateReportID();
      const activePolicyCategories = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${defaultExpensePolicy?.id}`] ?? {};
      for (const item of transactionList) {
      const existingTransactionID = getExistingTransactionID(item.linkedTrackedExpenseReportAction);
      const existingTransactionDraft = existingTransactionID ? transactionDrafts?.[existingTransactionID] : undefined;
      duplicateTransactionAction({
      transaction: item,
      optimisticChatReportID,
      optimisticIOUReportID,
      isASAPSubmitBetaEnabled,
      introSelected,
      quickAction,
      policyRecentlyUsedCurrencies: policyRecentlyUsedCurrencies ?? [],
      isSelfTourViewed,
      customUnitPolicyID: policy?.id,
      targetPolicy: defaultExpensePolicy ?? undefined,
      targetPolicyCategories: activePolicyCategories,
      targetReport: activePolicyExpenseChat,
      existingTransactionDraft,
      betas,
      personalDetails,
      recentWaypoints,
      targetPolicyTags,

    Substituting scenario 3 into the gate (step 4): the route report is the thread report → visibleTransactions.length stays 1 after duplication, and nothing optimistically marks that report multi‑transaction → useShowSuperWideRHPVersion(false) keeps the RHP at single‑expense width. That is exactly "stays on expense preview page." It's scenario‑3‑specific because only the non‑one‑transaction source path reassigns reportID to the thread (step 1); one‑transaction sources stay on the parent report and the gate flips naturally.

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

    After a successful duplicate, redirect to the destination report's table and optimistically widen it, reusing the exact mechanism Search/index.tsx already uses for multi‑transaction groups. In duplicateExpenseTransaction (useExpenseActions.ts) capture the destination report id (the optimisticIOUReportID the duplicate is built on, L231/L241) and, when the action originated from a single‑expense / transaction‑thread RHP, do:

    markReportIDAsMultiTransactionExpense(destinationReportID);
    Navigation.navigate(ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID: destinationReportID}));
    

    markReportIDAsMultiTransactionExpense makes useShowSuperWideRHPVersion render super‑wide immediately (before the optimistic transaction count catches up), and the pendingNewTransactionIDs flag added in #89585 then fires the row highlight on that table. Regression safety: this runs only on the duplicate path from a single‑expense RHP, so the one‑transaction scenarios (already correct) and the report‑table scenario are untouched — the destination report is the same report the duplicate lands in.

    Why the obvious one‑line fix fails: simply changing the gate to visibleTransactions.length >= 1, or only bumping markReportIDAsMultiTransactionExpense on the currently viewed report, does not work — the viewed thread report never receives the duplicate (step 4 creates it on a new optimisticIOUReportID), so its visible‑transaction count stays at 1 forever and the highlighted duplicate would not even live in that report. The redirect must target the destination report, not relax the count on the source thread.

    What alternative solutions did you explore? (Optional)

    1. Reassign less aggressively at the Search level — keep reportID as the parent report (don't jump to childReportID at Search/index.tsx#L546) so the RHP already shows the multi‑transaction table. Rejected: it changes the opening behavior for every multi‑transaction expense (you'd land on the table, not the single expense), which is the established UX and would regress the normal open flow.
    2. Fire the redirect from SearchMoneyRequestReportPage by watching pendingNewTransactionIDs on the parent report and navigating to its table. Rejected as the headline: it adds per‑render watching on a page that renders for every expense and re‑derives the parent from the thread, whereas the destination report id is already known for free inside the duplicate action — cheaper and more direct to navigate there.
  7. lorretheboy commented on Jun 24, 2026

    @lorretheboy
    Contributor

    Proposal

    What is the root cause of that problem?

    "Duplicate expense" from a single‑expense view never navigates anywhere, so the RHP stays on the source expense preview.

    In the transaction‑thread header (the exact repro path: Spend → Expenses → open one expense → More → Duplicate expense), the DUPLICATE action's onSelected just fires the duplicate and returns — there is no navigation, and the result (which carries the report the duplicate landed in) is discarded:

    const duplicateTransaction = (transactions: Transaction[]) => {
    if (!transactions.length) {
    return;
    }
    const optimisticChatReportID = generateReportID();
    const optimisticIOUReportID = generateReportID();
    const activePolicyCategoriesMap = defaultPolicyCategories ?? {};
    for (const item of transactions) {
    const existingTransactionID = getExistingTransactionID(item.linkedTrackedExpenseReportAction);
    const existingTransactionDraft = existingTransactionID ? transactionDrafts?.[existingTransactionID] : undefined;
    duplicateTransactionAction({
    transaction: item,
    optimisticChatReportID,
    optimisticIOUReportID,
    isASAPSubmitBetaEnabled,
    introSelected,
    quickAction,
    policyRecentlyUsedCurrencies: policyRecentlyUsedCurrencies ?? [],
    isSelfTourViewed,
    customUnitPolicyID: policy?.id,
    targetPolicy: defaultExpensePolicy ?? undefined,
    targetPolicyCategories: activePolicyCategoriesMap,
    targetReport: activePolicyExpenseChat,
    existingTransactionDraft,
    betas,
    personalDetails,
    recentWaypoints,
    targetPolicyTags,
    currentUser: {accountID, email: currentUserLogin ?? ''},
    currentUserLocalCurrency: localCurrencyCode ?? CONST.CURRENCY.USD,
    });
    }
    };

    Normal expense creation reaches the report/table view through navigateAfterExpenseCreate, but that runs in the confirmation flow. The duplicate path calls the action layer directly and bypasses confirmation, so no post‑create navigation runs.

    The only thing inside requestMoney that could surface the new expense is the chat→table highlight rail, and it is gated by isOneToTwoTransactionTransition. That gate fails here for two independent reasons: the duplicate is created against the active‑policy chat report (so isMoneyRequestReport is false), and it requires the target to currently hold exactly one non‑deleted transaction — but the repro report already has more than one:

    function isOneToTwoTransactionTransition(isMoneyRequestReport: boolean, transactions: Transaction[]) {
    return isMoneyRequestReport && transactions.filter((t) => t.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE).length === 1;
    }

    if (isOneToTwoTransactionTransition(isMoneyRequestReport, getReportTransactions(moneyRequestReportID))) {
    addPendingNewTransactionIDs(activeReportID, transaction.transactionID);
    }
    if (deferredAPIWrite) {
    deferOrExecuteWrite(deferredAPIWrite, {
    shouldDeferForSearch: false,
    isRetry: requestMoneyInformation.isRetry,
    optimisticWatchKey: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`,
    onDeferred: () => addOptimization(CONST.TELEMETRY.SUBMIT_OPTIMIZATION.DEFERRED_WRITE),
    });
    }
    if (!requestMoneyInformation.isRetry) {
    highlightTransactionOnSearchRouteIfNeeded(isFromGlobalCreate, transaction.transactionID, CONST.SEARCH.DATA_TYPES.EXPENSE);
    }
    if (activeReportID && !isMoneyRequestReport) {
    Navigation.setNavigationActionToMicrotaskQueue(() =>
    setTimeout(() => {
    notifyNewAction(activeReportID, reportPreviewAction, payeeAccountID === currentUserAccountIDParam);
    }, CONST.TIMING.NOTIFY_NEW_ACTION_DELAY),
    );
    }
    return {iouReport};

    So even the highlight machinery never engages, and nothing redirects.

    Crucially, the duplicate does not necessarily land in a brand‑new report. The wrapper passes targetReport: activePolicyExpenseChat and an optimisticIOUReportID, but no existingIOUReport. getMoneyRequestInformation therefore falls back to chatReport.iouReportID and reuses the chat's existing open expense report when one exists — the optimisticIOUReportID is discarded in that case:

    // STEP 2: Get the Expense/IOU report. If the existingIOUReport or moneyRequestReportID has been provided, we want to add the transaction to this specific report.
    // If no such reportID has been provided, let's use the chatReport.iouReportID property. In case that is not present, build a new optimistic Expense/IOU report.
    let iouReport: OnyxInputValue<OnyxTypes.Report> = null;
    if (existingIOUReport) {
    iouReport = existingIOUReport;
    } else if (moneyRequestReportID) {
    iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`] ?? null;
    } else if (!allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`]?.errorFields?.createChat) {
    iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`] ?? null;
    }
    const isScanRequest = isScanRequestTransactionUtils(existingTransaction);
    const shouldCreateNewMoneyRequestReport = isSplitExpense
    ? false
    : shouldCreateNewMoneyRequestReportReportUtils(iouReport, chatReport, isScanRequest, betas, action, !!moneyRequestReportID);
    // Generate IDs upfront so we can pass them to buildOptimisticExpenseReport for formula computation
    const optimisticTransactionID = existingTransactionID ?? providedOptimisticTransactionID ?? rand64();
    const optimisticReportID = optimisticIOUReportID ?? generateReportID();
    if (!iouReport || shouldCreateNewMoneyRequestReport) {

    This is why the redirect must target the report ID the action actually returns, not the optimistic ID.

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

    After duplicating a single expense, navigate to the report that received the duplicate and open it as a multi‑transaction (super‑wide) table, mirroring exactly how Search opens a multi‑transaction report on row press — markReportIDAsMultiTransactionExpense(reportID) followed by navigation to the table‑capable SEARCH_MONEY_REQUEST_REPORT route:

    if (item.transactions.length > 1) {
    markReportIDAsMultiTransactionExpense(reportID);
    } else {
    unmarkReportIDAsMultiTransactionExpense(reportID);
    }
    // Persist the current search context so prev/next navigation arrows
    // in the report RHP can reference the correct result set.
    saveLastSearchParams({
    queryJSON,
    offset,
    searchKey: currentSearchKey,
    hasMoreResults: !!searchResults?.search?.hasMoreResults,
    allowPostSearchRecount: true,
    });
    const route = ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID, backTo});
    if (openInternalRouteInNewTab(route, event)) {
    return;
    }
    requestAnimationFrame(() => Navigation.navigate(route));
    return;

    The route choice matters. SEARCH_REPORT mounts the chat ReportScreen (loadRHPReportScreen) and can never show the table; the table page (SearchMoneyRequestReportPage → MoneyRequestReportView) is mounted only by EXPENSE_REPORT / SEARCH_MONEY_REQUEST_REPORT:

    <Stack.Screen
    name={SCREENS.RIGHT_MODAL.SEARCH_REPORT}
    getComponent={loadRHPReportScreen}
    options={(props) => {
    const options = modalStackScreenOptions(props);
    return {...options, animation: animationEnabledOnSearchReport ? Animations.SLIDE_FROM_RIGHT : Animations.NONE};
    }}
    />
    <Stack.Screen
    name={SCREENS.RIGHT_MODAL.EXPENSE_REPORT}
    getComponent={loadSearchMoneyRequestReportPage}
    options={(props) => {
    const options = modalStackScreenOptions(props);
    return {...options, animation: isSmallScreenWidth ? Animations.SLIDE_FROM_RIGHT : Animations.NONE};
    }}
    />
    <Stack.Screen
    name={SCREENS.RIGHT_MODAL.SEARCH_MONEY_REQUEST_REPORT}
    getComponent={loadSearchMoneyRequestReportPage}
    options={(props) => {
    const options = modalStackScreenOptions(props);
    return {...options, animation: isSmallScreenWidth ? Animations.SLIDE_FROM_RIGHT : Animations.NONE};
    }}
    />

    The IOU duplicateExpenseTransaction action returns {iouReport} from requestMoney — the report the transaction was actually written to (reused or newly built), already accounting for the chatReport.iouReportID reuse above:

    return createExpenseByType({
    transactionType: getTransactionType(transaction),
    params,
    transaction,
    transactionDetails,
    waypoints,
    participants,
    policyRecentlyUsedCurrencies,
    quickAction,
    customUnitPolicyID,
    personalDetails,
    recentWaypoints,
    });
    }

    function requestMoney(requestMoneyInformation: RequestMoneyInformation): {iouReport?: OnyxTypes.Report} {

    The thin UI wrapper today throws that return value away:

    const duplicateTransaction = (transactions: Transaction[]) => {
    if (!transactions.length) {
    return;
    }
    const optimisticChatReportID = generateReportID();
    const optimisticIOUReportID = generateReportID();
    const activePolicyCategoriesMap = defaultPolicyCategories ?? {};
    for (const item of transactions) {
    const existingTransactionID = getExistingTransactionID(item.linkedTrackedExpenseReportAction);
    const existingTransactionDraft = existingTransactionID ? transactionDrafts?.[existingTransactionID] : undefined;
    duplicateTransactionAction({
    transaction: item,
    optimisticChatReportID,
    optimisticIOUReportID,
    isASAPSubmitBetaEnabled,
    introSelected,
    quickAction,
    policyRecentlyUsedCurrencies: policyRecentlyUsedCurrencies ?? [],
    isSelfTourViewed,
    customUnitPolicyID: policy?.id,
    targetPolicy: defaultExpensePolicy ?? undefined,
    targetPolicyCategories: activePolicyCategoriesMap,
    targetReport: activePolicyExpenseChat,
    existingTransactionDraft,
    betas,
    personalDetails,
    recentWaypoints,
    targetPolicyTags,
    currentUser: {accountID, email: currentUserLogin ?? ''},
    currentUserLocalCurrency: localCurrencyCode ?? CONST.CURRENCY.USD,
    });
    }
    };

    So the fix is: in the wrapper, only for the single‑expense case (transactions.length === 1), capture the returned iouReport, then call markReportIDAsMultiTransactionExpense(iouReport.reportID) and Navigation.navigate(ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID: iouReport.reportID})). markReportIDAsMultiTransactionExpense (from useWideRHPActions) makes useShowSuperWideRHPVersion render super‑wide immediately, and the pendingNewTransactionIDs highlight added in #89585 then fires on that table.

    The same gap exists in the report‑header variant, which should get the same treatment (or share a small helper):

    const duplicateExpenseTransaction = (transactionList: OnyxTypes.Transaction[]) => {
    if (!transactionList.length) {
    return;
    }
    const optimisticChatReportID = generateReportID();
    const optimisticIOUReportID = generateReportID();
    const activePolicyCategories = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${defaultExpensePolicy?.id}`] ?? {};
    for (const item of transactionList) {
    const existingTransactionID = getExistingTransactionID(item.linkedTrackedExpenseReportAction);
    const existingTransactionDraft = existingTransactionID ? transactionDrafts?.[existingTransactionID] : undefined;
    duplicateTransactionAction({
    transaction: item,
    optimisticChatReportID,
    optimisticIOUReportID,
    isASAPSubmitBetaEnabled,
    introSelected,
    quickAction,
    policyRecentlyUsedCurrencies: policyRecentlyUsedCurrencies ?? [],
    isSelfTourViewed,
    customUnitPolicyID: policy?.id,
    targetPolicy: defaultExpensePolicy ?? undefined,
    targetPolicyCategories: activePolicyCategories,
    targetReport: activePolicyExpenseChat,
    existingTransactionDraft,
    betas,
    personalDetails,
    recentWaypoints,
    targetPolicyTags,
    currentUser: {accountID: currentUserPersonalDetails?.accountID, email: currentUserPersonalDetails?.email ?? ''},
    currentUserLocalCurrency: currentUserPersonalDetails?.localCurrencyCode ?? CONST.CURRENCY.USD,
    });
    }
    };

    Keep the navigation in these UI wrappers, not in the IOU action, since bulk/report duplication reuses the action and must not redirect per expense — hence the transactions.length === 1 guard.

    What alternative solutions did you explore? (Optional)

    1. Navigate to the wrapper's optimisticIOUReportID instead of the returned iouReport.reportID. Rejected: when the active‑policy expense chat already has an open expense report, getMoneyRequestInformation reuses chatReport.iouReportID and discards optimisticIOUReportID (MoneyRequestBuilder.ts:1324-1330), so the navigation would point at a report ID that was never created. Using the action's return value is correct in both the reuse and the brand‑new‑report cases.

    2. Use the SEARCH_REPORT route after marking the report multi‑transaction. Rejected: SEARCH_REPORT mounts the chat ReportScreen, which has no table branch, so the view would never flip to the super‑wide table no matter how the report is marked.

    3. Drop the isMoneyRequestReport/exactly‑one‑transaction gate so addPendingNewTransactionIDs covers duplicating into a multi‑transaction report. That restores the highlight, but on its own it still won't redirect from the single‑expense RHP — an explicit navigation to the target report is required either way.

  8. aswin-s commented on Jun 24, 2026

    @aswin-s
    Contributor

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

    When a user opens a single expense whose underlying report has more than one transaction and taps More → Duplicate expense, the UI stays on the expense preview page instead of switching to the report's table view. The duplicated row does not receive the highlight animation and the RHP is not set to super-wide width. The expected behaviour is that the view navigates to the report table, the new duplicate row is highlighted, and the RHP renders in super-wide mode.

    What is the root cause of that problem?

    The DUPLICATE_EXPENSE action handler in src/hooks/useExpenseActions.ts (line 364) calls duplicateExpenseTransaction([transaction]), which only fires the Onyx write action. After the call returns, none of the three post-duplication steps are performed:

    1. markReportIDAsMultiTransactionExpense(reportID) is never called, so the RHP does not switch to super-wide mode.
    2. addPendingNewTransactionIDs(reportID, newTransactionID) is never called, so the report metadata never records the new transaction ID as pending-new — meaning the highlight system in useNewTransactions has no fallback signal when the table view mounts.
    3. Navigation.navigate to the report table route is never issued, so the user is left on the expense preview screen.

    In contrast, the Search list's row-select handler in src/components/Search/index.tsx always calls markReportIDAsMultiTransactionExpense(reportID) before navigating to a multi-transaction report (lines 582–584), and other expense-create flows call addPendingNewTransactionIDs so the highlight animation works on first load via the pendingNewTransactionIDs fallback path in useNewTransactions. The navigation, RHP-width, and pending-transaction-metadata steps were never wired into the single-expense duplicate flow.

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

    1. src/libs/actions/IOU/Duplicate.ts — duplicateExpenseTransaction (around line 743): Return the newly created transaction ID(s) alongside the existing return value (or add them to the existing result object) so the caller in useExpenseActions.ts can pass the correct IDs to addPendingNewTransactionIDs and Navigation.navigate. For example:
    // at the end of duplicateExpenseTransaction, include the new IDs in the return
    return { ..., newTransactionIDs };
    
    1. src/hooks/useExpenseActions.ts — duplicateExpenseTransaction wrapper (lines 226–260): After the duplicateTransactionAction loop completes, call addPendingNewTransactionIDs (imported from src/libs/actions/IOU/PendingNewTransactions) for each new transaction ID against the target report ID. This writes pendingNewTransactionIDs into Onyx report metadata so that when the table view mounts and useNewTransactions detects a 1→2 (or N→N+1) transition it can fall back to this metadata to identify which row to highlight:
    import {addPendingNewTransactionIDs} from '@libs/actions/IOU/PendingNewTransactions';
    
    // after duplicateTransactionAction loop:
    for (const newTransactionID of newTransactionIDs) {
        addPendingNewTransactionIDs(targetReportID, newTransactionID);
    }
    
    1. src/hooks/useExpenseActions.ts — same wrapper: Call markReportIDAsMultiTransactionExpense(targetReportID) from the WideRHPActionsContext (accessed via the existing useWideRHPActionsContext hook) to switch the RHP to super-wide mode before navigating, matching the behaviour in Search/index.tsx lines 582–584:
    const {markReportIDAsMultiTransactionExpense} = useWideRHPActionsContext();
    
    // after addPendingNewTransactionIDs calls:
    markReportIDAsMultiTransactionExpense(targetReportID);
    
    1. src/hooks/useExpenseActions.ts — same wrapper: Add Navigation.navigate to the report table route (e.g. ROUTES.SEARCH_REPORT.getRoute({reportID: targetReportID})) immediately after step 3, so the view switches to the report's table view after duplication.

    2. src/hooks/useExpenseActions.ts — DUPLICATE_EXPENSE onSelected handler (around line 364): Verify that the targetReportID resolved in step 2 is forwarded correctly from the handler into the wrapper — it should be the activePolicyExpenseChat?.reportID or the optimisticIOUReportID produced by duplicateExpenseTransaction.

    What alternative solutions did you explore? (Optional)

    Instead of returning the new transaction IDs from duplicateExpenseTransaction and calling addPendingNewTransactionIDs in the hook layer, the pending-transaction registration and navigation could be placed entirely inside Duplicate.ts itself, mirroring how bulkDuplicateExpenses handles navigation — but keeping navigation and UI-state logic in the hook layer is cleaner and more consistent with how Search/index.tsx manages the same steps. The addPendingNewTransactionIDs call must still happen regardless of which layer owns navigation, because without it the highlight animation is lost whenever the table view's component tree fresh-mounts (the 1→2 transaction transition causes MoneyRequestReportActionsList to remount, breaking the diff-based detection that useNewTransactions normally relies on).

  9. melvin-bot commented on Jun 24, 2026

    @melvin-bot

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

  10. changed the title [-]Expense - Duplicated expense does not redirect to report table view[/-] [+][$250] Expense - Duplicated expense does not redirect to report table view[/+] on Jun 24, 2026
  11. melvin-bot commented on Jun 24, 2026

    @melvin-bot
  12. neerajbachani commented on Jun 24, 2026

    @neerajbachani
    Contributor

    Proposal

    What is the root cause of that problem?

    When a user duplicates an expense from the single-expense preview (wide RHP on Spend → Expenses), the app only runs the create path (duplicateExpenseTransaction → requestMoney). It never runs the post-create navigation that normal expense submission uses.

    Normal expense creation from the same preview goes through SubmitExpenseOrchestrator.handleReportInRHPDismiss, which calls dismissRHPToReport and navigates to SEARCH_MONEY_REQUEST_REPORT when the destination report already has transactions. Duplicate expense has no equivalent step, so the UI stays on the expense preview.

    Highlighting is also incomplete: PR #89585 added pendingNewTransactionIDs in MoneyRequestBuilder and a small useNewTransactions tweak so the new row animates after navigation. That work was reverted in #94367, so even if we only add navigation, the duplicate row may not highlight reliably on the table.

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

    1. Add post-duplicate navigation (main fix)

    Create src/libs/Navigation/helpers/navigateAfterDuplicateExpense.ts that mirrors dismissRHPToReport from submitDismissStrategies.ts:

    • Only run when the user is in the expense RHP (isReportOpenInRHP).
    • If super-wide RHP is open, dismissToPreviousRHP (back to table).
    • If the destination report already has transactions, navigate to SEARCH_MONEY_REQUEST_REPORT.
    • Otherwise pop the RHP (single-tx report case).

    Call it at the end of duplicateExpenseTransaction after createExpenseByType / trackExpense return, using result?.iouReport?.reportID.

    Minimal sketch:

    // Duplicate.ts — after createExpenseByType / trackExpense
    const result = createExpenseByType({...});
    navigateAfterDuplicateExpense(result?.iouReport?.reportID);
    return result;
    
    // navigateAfterDuplicateExpense.ts — core branch
    if (!isReportOpenInRHP(rootState)) return;
    if (hasExistingTransactions) {
        Navigation.navigate(ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID}));
    }
    

    2. Restore highlight metadata (partial re-apply of #89585)

    In MoneyRequestBuilder.ts, write pendingNewTransactionIDs in optimistic data and clear it in success/failure data so useNewTransactions can highlight the new row after cross-navigation.

    // MoneyRequestBuilder — optimisticData
    pendingNewTransactionIDs: {[transaction.transactionID]: true}
    // successData / failureData
    pendingNewTransactionIDs: {[transaction.transactionID]: null}
    

    3. Fix useNewTransactions focus guard (partial re-apply of #89585)

    In useNewTransactions.ts, remove the early isFocused === false return so the transaction diff can queue a highlight while the table view mounts. Keep the pendingNewTransactionIDs path gated by isFocused so unfocused chat previews do not consume the flag early.

    What alternative solutions did you explore? (Optional)

    • Navigation in UI only (MoneyRequestHeaderSecondaryActions / useExpenseActions): Rejected because bulk duplicate and other entry points would miss the fix; the action layer already knows the destination iouReport.reportID.
    • Reuse handleNavigateAfterExpenseCreate: That helper is built for global-create / inbox flows, not "duplicate from expense preview in Search RHP."
  13. 31 remaining items

  14. melvin-bot commented on Jul 3, 2026

    @melvin-bot

    @abzokhattab Whoops! This issue is 2 days overdue. Let's get this updated quick!

  15. melvin-bot commented on Jul 3, 2026

    @melvin-bot

    @abzokhattab Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  16. melvin-bot commented on Jul 7, 2026

    @melvin-bot

    @abzokhattab 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

  17. melvin-bot commented on Jul 9, 2026

    @melvin-bot

    @abzokhattab 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it!

  18. melvin-bot commented on Jul 9, 2026

    @melvin-bot

    @abzokhattab 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it!

  19. abzokhattab commented on Jul 12, 2026

    @abzokhattab
    Contributor

    @blimpich should we close this issue, it looks to be duplciate to the already open issue here ... ref

  20. melvin-bot commented on Jul 15, 2026

    @melvin-bot

    @abzokhattab Whoops! This issue is 2 days overdue. Let's get this updated quick!

  21. melvin-bot commented on Jul 17, 2026

    @melvin-bot

    @abzokhattab Eep! 4 days overdue now. Issues have feelings too...

  22. abzokhattab commented on Jul 19, 2026

    @abzokhattab
    Contributor

    PR got merged .. we can close this one @blimpich

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.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions