Skip to content

[Due for payment 2025-12-17] [$250] Reports - Device back button redirects to previous section but selection mode remains. #74585

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: 9.2.46-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: #70877
Email or phone of affected tester (no customers): ibellicotest+2022@gmail.com
Issue reported by: Applause Internal Team
Device used: Motorola MotoG60 / Android 12 / Chrome ( mWeb) - Windows 11 / Chrome
App Component: Search

Action Performed:

Prerequisite: Account has at least one workspace.
Prerequisite 2: Delayed submissions enabled.

  1. Open the staging.new.expensify.com website.
  2. Open any workspace chat.
  3. Create a manual expense or empty report.
  4. Navigate to "Reports" > "Submit" and from there to "Reports" > "Reports"
  5. Select the just created expense.
  6. Use device back button.
  7. Note that you land on "Submit" again and expense is still selected.

Expected Result:

When using back button during selection mode, expense shouldn´t be displayed selected anymore and user should remain on the same section.

Actual Result:

When using back button during selection mode, user lands on previous section and expense is still selected.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug6996740_1762495287403.Mode.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021990620962377833114
  • Upwork Job ID: 1990620962377833114
  • Last Price Increase: 2025-11-25
  • Automatic offers:
    • FitseTLT | Contributor | 109633534
Issue OwnerCurrent Issue Owner: @strepanier03

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Nov 7, 2025
  2. melvin-bot commented on Nov 7, 2025

    @melvin-bot

    Triggered auto assignment to @strepanier03 (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  3. TaduJR commented on Nov 7, 2025

    @TaduJR
    Contributor

    Proposal

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

    When pressing the back button while items are selected in Reports search, the user navigates to the previous section (e.g., "Reports" to "Submit"), but selections remain visible and mobile selection mode stays enabled on mWeb platforms.

    What is the root cause of that problem?

    The cleanup effect that clears selections early returns when navigating between search pages:

    useEffect(
    () => () => {
    if (isSearchTopmostFullScreenRoute()) {
    return;
    }
    clearSelectedTransactions();
    turnOffMobileSelectionMode();
    },
    [isFocused, clearSelectedTransactions],
    );

    When navigating from "Reports" to "Submit" (both are search pages), isSearchTopmostFullScreenRoute() returns true for both, so the cleanup is skipped and selections persist.

    Additionally, the back button handler only works on Android native, not mWeb:

    Android:

    export default function useHandleBackButton(callback: UseHandleBackButtonCallback) {
    useFocusEffect(
    useCallback(() => {
    const backHandler = BackHandler.addEventListener('hardwareBackPress', callback);
    return () => backHandler.remove();
    }, [callback]),
    );
    }

    mWeb (no-op):

    export default function useHandleBackButton(_callback: UseHandleBackButtonCallback) {}

    On mWeb, browser back navigation happens without clearing selections.

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

    Add hash comparison to the cleanup effect so it only skips for the same search page.

    Step 1: Add currentSearchHash to destructured variables

    const {
    setCurrentSearchHashAndKey,
    setCurrentSearchQueryJSON,
    setSelectedTransactions,
    selectedTransactions,
    clearSelectedTransactions,
    shouldTurnOffSelectionMode,
    setShouldShowFiltersBarLoading,
    lastSearchType,
    shouldShowSelectAllMatchingItems,
    areAllMatchingItemsSelected,
    selectAllMatchingItems,
    shouldResetSearchQuery,
    setShouldResetSearchQuery,
    } = useSearchContext();

    Add currentSearchHash as the first property in the destructuring at line 244:

    const {
        currentSearchHash,
        setCurrentSearchHashAndKey,
        // ... rest
    } = useSearchContext();
    

    Step 2: Update cleanup effect

    useEffect(
    () => () => {
    if (isSearchTopmostFullScreenRoute()) {
    return;
    }
    clearSelectedTransactions();
    turnOffMobileSelectionMode();
    },
    [isFocused, clearSelectedTransactions],
    );

    Change line 585 from:

    if (isSearchTopmostFullScreenRoute()) {
    

    To:

    if (isSearchTopmostFullScreenRoute() && currentSearchHash === hash) {
    

    Also update line 591 dependencies from:

    [isFocused, clearSelectedTransactions],
    

    To:

    [isFocused, clearSelectedTransactions, currentSearchHash, hash],
    

    This clears selections and turns off mobile selection mode when navigating between different search pages, fixing both the original issue and mWeb behavior.

    What alternative solutions did you explore? (Optional)

    Prevent selection restoration:
    Add hash check at selection restoration effect to prevent restoring with stale data. However, this doesn't turn off mobile selection mode.

    Implement web back button handler:
    Add History API handling to useHandleBackButton for web. More complex and fragile than using existing cleanup effect.

  4. daledah commented on Nov 7, 2025

    @daledah
    Contributor

    Proposal

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

    When using back button during selection mode, user lands on previous section and expense is still selected.

    What is the root cause of that problem?

    1. Users select some options, we'll store it in selectedTransactions
    2. Users go back to the previous page, we'll reset these selected data

    clearSelectedTransactions();

    1. In the new page, we trigger setSelectedTransactions with the selectedTransactions from useSearchContext

    setSelectedTransactions(newTransactionList, data);

    at this time, selectedTransactions hasn't been cleared yet so selectedTransactions will be preserved

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

    1. We shouldn't trigger setSelectedTransactions if the data is still clearing. To do that we can add this check
           if (currentSearchHash !== hash) {
                return;
            }
    

    in

    useEffect(() => {

    This way will make sure the selectedTransactions used in this hook is up to date.

    1. To prevent the selection mode showing while going back we need

    Clear the mobile selection mode like we did in

    useEffect(() => {
    return () => {
    turnOffMobileSelectionMode();
    };
    }, []);

    useEffect(() => {
            return () => {
                turnOffMobileSelectionMode();
            };
        }, []);
    

    Then in

    useEffect(() => {

    We also need to prevent enable mobile selection mode while the hash is updating

        if (currentSearchHash !== hash) {
                    return;
        }
    
    Screen_Recording_2025-11-24_at_23.28.48.mov

    What alternative solutions did you explore? (Optional)

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  5. FitseTLT commented on Nov 7, 2025

    @FitseTLT
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2025-11-24 16:52:55 UTC.

    Proposal

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

    Reports - Device back button redirects to previous section but selection mode remains.

    What is the root cause of that problem?

    We already have a logic to reset selection and mobile selection mode when focus is lost from search page but it early returns if we are currently on search route

    () => () => {
    if (isSearchTopmostFullScreenRoute()) {
    return;
    }
    clearSelectedTransactions();
    turnOffMobileSelectionMode();
    },
    [isFocused, clearSelectedTransactions],

    so when we go back to another search page with different hash it early returns from resetting the selection

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

    We should also make sure that the hash is the same as the currentSearchHash in addition to isSearchTopmostFullScreenRoute so that we reset whenever the search query is changed while we are on search page

        
    if (isSearchTopmostFullScreenRoute() && currentSearchHash === hash) {
                    return;
                }
    

    For mWeb, there is another bug that wrongly re-enables the mobile selection mode. It is caused by this effect below

    turnOnMobileSelectionMode();
    }
    // eslint-disable-next-line react-compiler/react-compiler
    // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [isSmallScreenWidth, selectedTransactions, isMobileSelectionModeEnabled]);

    When we clear the selection and turn off mobile mode here the mobile selection mode value (from onyx) gets updated before the selectedTransactions is cleared so the effect above turnOnMobileSelectionMode because selectedKeys is not empty while isMobileSelectionModeEnabled is false.
    Solution: this effect is needed only when the screen width changes to either turn on or off the selection mode as needed so the dependency should only be
    }, [isSmallScreenWidth, selectedTransactions, isMobileSelectionModeEnabled]);

        }, [isSmallScreenWidth]);
    

    What alternative solutions did you explore? (Optional)

  6. melvin-bot commented on Nov 12, 2025

    @melvin-bot

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

  7. melvin-bot commented on Nov 15, 2025

    @melvin-bot

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

  8. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Nov 18, 2025
  9. melvin-bot commented on Nov 18, 2025

    @melvin-bot
  10. changed the title [-]Reports - Device back button redirects to previous section but selection mode remains.[/-] [+][$250] Reports - Device back button redirects to previous section but selection mode remains.[/+] on Nov 18, 2025
  11. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Nov 18, 2025
  12. 45 remaining items

  13. strepanier03 commented on Dec 18, 2025

    @strepanier03
    Contributor

    Payment Summary

  14. strepanier03 commented on Dec 18, 2025

    @strepanier03
    Contributor

    HEADS UP

    I am OoO starting 12-19 and will return on 12-29.

    If this GH needs attention or action during that time period, please reapply the BugZero label to assign someone to help out, but leave me assigned as well. Alternatively, you can post in Slack for a BZ buddy to take action.

    Otherwise, I will catch up on issues that need attention when I get back.

  15. Krishna2323 commented on Dec 23, 2025

    @Krishna2323
    Contributor

    Will complete the checklist today.

  16. melvin-bot commented on Dec 23, 2025

    @melvin-bot

    @strepanier03 Huh... This is 4 days overdue. Who can take care of this?

  17. melvin-bot commented on Dec 25, 2025

    @melvin-bot

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

  18. Krishna2323 commented on Dec 26, 2025

    @Krishna2323
    Contributor

    BugZero Checklist:

    • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment: [Search] Move selectedTransactions array to SearchContext #46406 (comment)

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion: N/A

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue: https://github.com/Expensify/Expensify/issues/582796

    Regression Test Proposal

    Precondition:

    • Account has at least one workspace.
    • Delayed submissions enabled.

    Test:

    1. Open any workspace chat.
    2. Create a manual expense.
    3. Navigate to "Reports" > "Reports" and from there navigate to "Reports" > "Submit"
    4. Select the just created expense.
    5. Use
      1. Native: device back button
      2. Web: device or browser back button
    6. Verify that
      1. Web: you are navigated back to "Reports" > "Reports" section with the selection and selection mode reset.
      2. Native: only the selection and selection mode is reset while the page is still in "Reports" > "Submit" page

    Do we agree 👍 or 👎

    Zapier Logs Run ID: 00040eee-0627-a256-b777-0bf7d2bbf824
  19. strepanier03 commented on Dec 30, 2025

    @strepanier03
    Contributor

    Reg test is made and I removed the hold from the payment summary. Thanks @Krishna2323, closing out.

  20. Krishna2323 commented on Jan 17, 2026

    @Krishna2323
    Contributor

    Requested in ND.

  21. twisterdotcom commented on Jan 18, 2026

    @twisterdotcom
    Contributor

    @Krishna2323 has submitted payment for this report on ND here.

    SO: https://stackoverflowteams.com/c/expensify/questions/7582

    Zapier Logs Run ID: 00040eee-7899-a014-a757-30172330e5f4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething 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