Skip to content

[$250] Duplicate expense-There is no duplicate expense option until reselecting all expense #87599

Closed

Description

@nlemma

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: v9.3.58-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: #84657
Email or phone of affected tester (no customers): testpayment935@gmail.com
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: Windows 11 pro /Chrome
App Component: Money Requests

Action Performed:

  1. Navigate to staging.new.expensify.com
  2. Create an expense and duplicate until it become 100 or more expense in report page
  3. Submit and approve all in the WS chat ( Keep all expense in duplicate review page
  4. After the report loads correctly, go to report page and select all
  5. Note only 50 of the expense are loaded
  6. Click "select all matching item" scroll down to include the remining expense
  7. Click drop down of all matching item selected
  8. Note there is no duplicate expense option
  9. Unselect all expense and select again

Expected Result:

In step 8 there should be a duplicate expense option

Actual Result:

In step 8 there is no duplicate expense option until unselect and select all the expenses again

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7126610_1775816445403.bandicam_2026-04-10_13-03-41-672.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022042606189679731536
  • Upwork Job ID: 2042606189679731536
  • Last Price Increase: 2026-04-10

Activity

  1. added
    DeployBlockerCash
    Daily
    Bug
    on Apr 10, 2026
  2. melvin-bot commented on Apr 10, 2026

    @melvin-bot

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

  3. melvin-bot commented on Apr 10, 2026

    @melvin-bot

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

  4. github-actions commented on Apr 10, 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 Apr 10, 2026

    @OSBotify
    Contributor

    Investigation Summary - Classification: Frontend bug. Causing PR: 84657 "[Duplicate Expense] Allow bulk duplication." by @Krishna2323 (High confidence). Recommendation: REVERT. The causing PR introduced the bulk duplicate option but its visibility check fails when the report has more than 50 expenses and select-all-matching-items is used, because not all selected transactions are loaded in the Onyx store at that time. Assigned: @Krishna2323 (PR author), @JS00001 @situchan (approving reviewers). Labels: DeployBlockerCash kept (frontend bug in App repo). Root Cause: shouldShowBulkDuplicateOption uses Array.every() against allTransactions (Onyx in-memory store). When select-all-matching-items selects more transaction IDs than are loaded in the current page (50 per page), the unloaded transactions are absent from allTransactions causing every() to return false and isDuplicateOptionVisible to be false - hiding the duplicate option. Evidence: Bug is staging-only and was introduced by PR 84657 (merged 2026-04-09). The hook useSelectedTransactionsActions.ts lines 158-195 builds selectedTransactionsForDuplicate and calls shouldShowBulkDuplicateOption. When the paginated list only loads 50 items but 100+ are selected, the unloaded transaction IDs fail the lookup. The workaround of deselect-and-reselect works because it only selects the visible 50, which are all in Onyx.

  6. MelvinBot commented on Apr 10, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    When a user clicks "Select all matching items," the flag areAllMatchingItemsSelected is set to true (SearchContext.tsx:105). In useSearchBulkActions.ts, the bulk actions computation early-returns with only the Export option when this flag is true:

    if (areAllMatchingItemsSelected) {
        return [exportButtonOption];
    }

    This means the "Review duplicates" option (added at line 1328) is never reached. When the user deselects and reselects, clearSelectedTransactions resets areAllMatchingItemsSelected to false, so the early return is skipped and the full set of bulk actions (including duplicates) is computed.

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

    The early return at useSearchBulkActions.ts:1027-1029 should be updated to also include bulk action options that can work with the "all matching" selection — specifically the "Duplicate expense" option. The isDuplicateOptionVisible check and the duplicate option should be evaluated before the early return, so that when areAllMatchingItemsSelected is true, the returned array includes both Export and (if applicable) Duplicate.

    What alternative solutions did you explore?

    An alternative would be to remove the early return entirely and instead guard each individual bulk action that requires full client-side data. However, this would be a larger refactor with more risk. The targeted fix of moving the duplicate option evaluation before the early return is simpler and lower risk.


    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.

  7. situchan commented on Apr 10, 2026

    @situchan
    Contributor

    This feature is gated behind production so we can demote.

  8. 3 remaining items

  9. Krishna2323 commented on Apr 10, 2026

    @Krishna2323
    Contributor

    @situchan @JS00001 this affects all bulk actions, not just duplicate. It's a pre-existing behavior that our PR didn't introduce. The flag areAllMatchingItemsSelected is a separate concept from "every visible item is checked" and doesn't auto-resolve when all items become loaded.

    Monosnap.screencast.2026-04-10.19-31-25.mp4
  10. situchan commented on Apr 10, 2026

    @situchan
    Contributor

    Agree. I also noticed this while testing PR but not reported because it's existing behavior.

  11. JS00001 commented on Apr 10, 2026

    @JS00001
    Contributor

    Cool, lets make it external then

  12. added
    External
    Help Wanted
    on Apr 10, 2026
  13. melvin-bot commented on Apr 10, 2026

    @melvin-bot

    Current assignees @Krishna2323 and @situchan are eligible for the External assigner, not assigning anyone new.

  14. melvin-bot commented on Apr 10, 2026

    @melvin-bot
  15. changed the title [-]Duplicate expense-There is no duplicate expense option until reselecting all expense[/-] [+][$250] Duplicate expense-There is no duplicate expense option until reselecting all expense[/+] on Apr 10, 2026
  16. Krishna2323 commented on Apr 10, 2026

    @Krishna2323
    Contributor

    @JS00001 I don't think this needs a fix, seems intentional. @MelvinBot can you confirm?

  17. MelvinBot commented on Apr 10, 2026

    @MelvinBot
    Contributor

    Yes, this is intentional. The early return at useSearchBulkActions.ts:1027-1029 restricts bulk actions to Export only when areAllMatchingItemsSelected is true — and this applies to all non-export bulk actions (approve, pay, delete, hold, merge, etc.), not just duplicate.

    Why: "Select all matching items" logically selects items on unloaded pages (only the first 50 are loaded client-side). Export works because it sends the search query (jsonQuery) to the server for server-side resolution. Every other bulk action requires per-transaction client-side data (action, canHold, canApprove, etc.) that doesn't exist for unloaded items.

    Supporting evidence
    • The export path at line 356-364 sends the full jsonQuery to the server with empty ID lists when areAllMatchingItemsSelected is true
    • Post-early-return code at line 1031+ iterates selectedTransactions and checks per-transaction properties — this requires loaded transaction objects
    • The flag is set at SearchContext.tsx:105 and specifically represents items beyond the loaded view, as noted in the comment at Search/index.tsx:933-934

    Supporting other bulk actions for "select all matching" would require server-side implementations similar to export — that would be a feature request, not a bug fix.

  18. JS00001 commented on Apr 10, 2026

    @JS00001
    Contributor

    Oh yeah, I misread this one, this is expected, sorry

  19. KJ21-ENG commented on Apr 10, 2026

    @KJ21-ENG
    Contributor

    Proposal

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

    When handling duplicate expenses, the duplicate-expense action is missing right after selecting the report, and only appears after reselecting the report.

    What is the root cause of that problem?

    The bulk-action availability for duplicate handling depends on selected transactions/reports from search results, but those results can briefly become empty during the report-selection refresh cycle.

    SearchContext returns snapshot-based search data for non to-do searches, so transient empty snapshots can occur while the selected report context is changing.

    // If viewing a to-do search, use live data from useTodos, otherwise return the snapshot data
    // We do this so that we can show the counters for the to-do search results without visiting the specific to-do page, e.g. show `Approve [3]` while viewing the `Submit` to-do search.
    function getCurrentSearchResults(): SearchResults | undefined {
    if (shouldUseLiveData) {
    const liveData = todoSearchResultsData[currentSearchKey as keyof typeof todoSearchResultsData];
    const searchInfo: SearchResultsInfo = {
    ...(snapshotSearchResults?.search ?? defaultSearchInfo),
    count: liveData.metadata.count,
    total: liveData.metadata.total,
    currency: liveData.metadata.currency,
    };
    const hasResults = Object.keys(liveData.data).length > 0;

    In useSearchBulkActions, option eligibility for all-selected mode should use the last non-empty result set. Without that fallback, the merge/duplicate action disappears until results repopulate.

    // Cache the last search results that had data, so the merge option remains available
    // while results are temporarily unset (e.g. during sorting/loading).
    const lastNonEmptySearchResultsRef = useRef<SearchResults | undefined>(undefined);
    useEffect(() => {
    if (!currentSearchResults?.data) {
    return;
    }
    lastNonEmptySearchResultsRef.current = currentSearchResults;
    }, [currentSearchResults]);
    const searchResults = currentSearchResults?.data ? currentSearchResults : lastNonEmptySearchResultsRef.current;
    const [isOfflineModalVisible, setIsOfflineModalVisible] = useState(false);

    return (fullReport?.transactionCount ?? 0) === 0;
    }) ?? [];
    const hasOnlyEmptyReports = selectedReports.length > 0 && emptyReports.length === selectedReports.length;
    if (hasOnlyEmptyReports) {
    setEmptyReportsCount(emptyReports.length);
    setIsDownloadErrorModalVisible(true);
    return;
    }
    if (isOffline) {
    setIsOfflineModalVisible(true);
    return;
    }
    if (areAllMatchingItemsSelected) {
    queueExportSearchWithTemplate({
    templateName,
    templateType,

    return;
    }
    if (status === null || status === undefined) {
    return;
    }
    if (areAllMatchingItemsSelected) {
    const result = await showConfirmModal({
    title: translate('search.exportSearchResults.title'),
    prompt: translate('search.exportSearchResults.description'),
    confirmText: translate('search.exportSearchResults.title'),
    cancelText: translate('common.cancel'),
    });
    if (result.action !== ModalActions.CONFIRM) {
    return;
    }
    if (selectedTransactionsKeys.length === 0 || status == null || !hash) {
    return;
    }

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

    1. Keep duplicate/merge eligibility tied to a stable cached non-empty search result set during short refresh windows.
    2. Use the cached selected reports/transactions when areAllMatchingItemsSelected is true and current snapshot is temporarily empty.
    3. Ensure action-option computation is deterministic across the report-selection transition so users do not lose the duplicate-expense option.
    4. Add regression coverage for the sequence: select report -> immediate duplicate action check -> no reselect needed.

    What alternative solutions did you explore? (Optional)

    An alternative is delaying menu rendering until search results repopulate, but that adds UI latency and can feel unresponsive. Keeping the action state stable with cached non-empty results is simpler and preserves UX continuity.

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

Metadata

Metadata

Labels

BugDailyEngineeringExternalHelp Wanted

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions