You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[$250] Spends - Selection mode does not automatically exit when selection count drops to zero #93911
Version Number: 9.4.10-2 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack:#92809 Email or phone of affected tester (no customers):applausetester+bm890@applause.expensifail.com Issue reported by: Applause Internal Team Bug source: Pull Request QA execution Device used: Web, android App Component: Chat Report View
Action Performed:
Go to staging.new.expensify.com
Go to Spends page.
Long-press a row to enter selection mode.
Deselect rows until the selection count drops to zero.
Expected Result:
Selection mode should automatically exit when selection count drops to zero.
Actual Result:
Selection mode remains active when selection count is zero.
Please re-state the problem that we are trying to solve in this issue.
On narrow/mobile layout, after long-pressing to enter selection mode and then deselecting rows until the selected count reaches zero, selection mode stays active. It should automatically exit when the selection drops to zero.
What is the root cause of that problem?
The effect that exits mobile selection mode when the selection becomes empty is gated on three conditions, and the third one (shouldTurnOffSelectionMode) is never true for a manual deselect:
shouldTurnOffSelectionMode is only set to true by explicit bulk-action clears (clearSelectedTransactions(..., true) — approve/pay/export, etc. at SearchSelectionProvider.tsx:136). Every per-row toggle/deselect instead goes through applySelection, which hardcodes the flag to false on every commit:
So when you manually deselect down to zero: selectedKeys.length === 0 ✅ and isMobileSelectionModeEnabled ✅, but shouldTurnOffSelectionMode === false ❌, so turnOffMobileSelectionMode() is never called and selection mode stays on.
Note the wide-layout branch already does the right thing — it turns selection mode off on empty with only the two-condition check (no shouldTurnOffSelectionMode gate): SearchWriteActionsProvider.tsx:312-315.
What changes do you think we should make in order to solve the problem?
Drop the shouldTurnOffSelectionMode condition from useTurnOffSelectionModeWhenEmpty so it exits selection mode whenever the selection is empty while in mobile selection mode and focused — mirroring the wide-layout branch:
Update the effect deps accordingly (drop shouldTurnOffSelectionMode). After this, the shouldTurnOffSelectionMode flag is still useful for the explicit bulk-action clear path, but it no longer blocks the manual deselect-to-zero case.
The deselect itself correctly empties the map (prepareTransactionsList deletes the key in selectionBuilders.ts), so selectedTransactions does become {} — the only thing blocking exit is the guard.
Alternative considered: set shouldTurnOffSelectionMode: true inside applySelection when the resulting map is empty. This is more surgical but couples a state-setter to selection-mode UX and risks the flag lingering true into the next render; removing the guard (matching the already-correct wide-layout branch) is simpler and more consistent.
Verification caveat: this bug reproduces in production per the report, and the pre-/post-PR effect bodies are byte-identical, so this is most likely a pre-existing latent bug that PR Search selection: move write-side off <Search> onto provider/controller #92809's test step 6 surfaced rather than a behavior change introduced by that PR. The static code path that blocks exit is deterministic, but a quick narrow-layout manual repro (deselect last row, confirm selection mode persists) is worth doing before merging the fix.
Next Steps for Contributor+ team: To accept:@MelvinBot implement [this](https://github.com/Expensify/App/issues/93911) to create a draft PR. To refine:@MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.
Please re-state the problem that we are trying to solve in this issue.
On a small-screen / mobile search view (the "Spends" list), long-pressing a row enters mobile selection mode. When the user then deselects rows one-by-one until the selection count reaches zero, selection mode stays active instead of automatically exiting. The expectation (and the behavior of every other selectable list in the app) is that emptying the selection by hand should drop the user back out of selection mode.
What is the root cause of that problem?
The Spends list renders through <Search>, which mounts SearchWriteActionsProvider. That provider owns the two effects that drive mobile selection mode. The one responsible for turning the mode off when the selection empties is useTurnOffSelectionModeWhenEmpty, and it only fires turnOffMobileSelectionMode() when an extra flag, shouldTurnOffSelectionMode, is also true:
The problem is that shouldTurnOffSelectionMode is never true on the manual-deselect path. Deselecting a row goes through toggle → applySelection, and every commit in applySelection hard-resets the flag back to false:
The only thing that sets shouldTurnOffSelectionMode: true is clearSelectedTransactions(..., true), and every caller of that is a bulk-action completion path — submitting a hold/reject reason, export, change-report, edit-multiple, etc. (useSelectedTransactionsActions, useExportActions, useSearchBulkActions, SearchHoldReasonPage...). In other words, this flag exists to wipe the selection and leave selection mode after an action runs; it was never meant to cover "the user emptied the selection themselves." So when the last checkbox is unticked, the effect re-runs (its deps include selectedTransactions), sees selectedKeys.length === 0, but shouldTurnOffSelectionMode is already false, and the mode is left on.
The sibling effect useSyncMobileSelectionModeWithScreenSize does not save us either: on the small-screen path it only ever turns the mode on, and its only zero-count turnOffMobileSelectionMode() is gated behind !isSmallScreenWidth. Its dependency array is [isSmallScreenWidth] only, so it deliberately never re-runs on selection changes.
The net effect is that the Search write-side has no effect that mirrors the app-wide convention. Every other selectable list uses useHandleSelectionMode, which calls turnOffMobileSelectionMode() whenever selectedItems.length === 0 with no extra flag gate (only a wasSelectionOnRef guard so it doesn't fire on first entry). That hook is exactly what SelectionListWithModal wires up, and it is the behavior QA is comparing against.
What changes do you think we should make in order to solve the problem?
Make useTurnOffSelectionModeWhenEmpty exit selection mode when the selection empties on the small-screen path, regardless of shouldTurnOffSelectionMode. The shouldTurnOffSelectionMode branch should stay (it still serves the post-bulk-action "clear + exit" case where the selection is wiped programmatically), but we add the manual-deselect case alongside it so the effect matches the useHandleSelectionMode convention. Concretely, in SearchWriteActionsProvider.tsx, pass isSmallScreenWidth into the hook and broaden the condition:
This is safe because the body only runs after the screen is focused (the early isFocused return is kept) and only when nothing is selected and the mode is currently on — so it can't interfere with an in-flight reconcile (which leaves at least one key) or with entering selection mode (which always selects the long-pressed row first in turnOnSelectionMode, so selectedKeys is never empty at entry). It also doesn't disturb the wide-screen behavior, which is already handled by useSyncMobileSelectionModeWithScreenSize. Restricting the new branch to isSmallScreenWidth keeps the change scoped to the platform where mobile selection mode actually exists, and the effect already re-runs on selectedTransactions changes so the exit happens the moment the count hits zero.
What alternative solutions did you explore? (Optional)
I considered replacing the whole custom pair of Search effects with the shared useHandleSelectionMode(selectedKeys) hook for consistency, but the Search write-side intentionally keeps shouldTurnOffSelectionMode and the reconcile-aware select-all logic that useHandleSelectionMode doesn't know about, so swapping wholesale risks regressing the bulk-action and select-all flows; the targeted condition change keeps those intact while restoring the expected exit-at-zero behavior.
Please re-state the problem that we are trying to solve in this issue.
On the Spends page (and other Search list views), after long-pressing a row to enter mobile selection mode and then deselecting rows until the selection count drops to zero, selection mode stays active. It should automatically exit once nothing is selected.
What is the root cause of that problem?
The Search selection feature has a dedicated effect whose job is exactly this — turn mobile selection mode off once nothing is selected:
That flag is committed to selection state in applySelection, which is the write path every row/checkbox toggle (including deselection) goes through. applySelection hardcodes the flag to false on every commit:
So when the user manually deselects rows down to zero, applySelection resets shouldTurnOffSelectionMode to false, and the turn-off effect never runs. The flag is only ever set to true by clearSelectedTransactions(..., true), which is called after bulk actions (reject/hold/edit-multiple) complete — i.e. only a programmatic clear can currently exit selection mode, not a manual deselect-to-zero.
What changes do you think we should make in order to solve the problem?
In applySelection (in src/components/Search/SearchSelectionProvider.tsx), instead of hardcoding shouldTurnOffSelectionMode: false in the committed state, derive it from whether the resulting selection is empty — set it to true when the new selectedTransactions map is empty and false otherwise. isEmptyObject is already imported in this file, so the value becomes isEmptyObject(selectedTransactions) (using the updated map computed a few lines above).
With this change, when a toggle deselects the last selected row, the committed selection is empty, shouldTurnOffSelectionMode becomes true, and the existing useTurnOffSelectionModeWhenEmpty effect fires and exits mobile selection mode — matching the expected behavior.
This also preserves the guard that protects entry into selection mode: long-pressing a row turns selection mode on and immediately toggles the long-pressed item, so the committed selection is non-empty and the flag stays false — the mode is not turned off the instant it is turned on.
What alternative solutions did you explore? (Optional)
Removing the && shouldTurnOffSelectionMode condition from the turn-off effect so it fires whenever the selection is empty. This was rejected because that flag also guards the entry race: when selection mode is turned on, there can be a render where mobile selection mode is enabled but the selection map is still empty (before the long-pressed item's toggle commits). Without the flag, the effect would immediately turn selection mode back off. Driving the flag from the committed selection's emptiness in applySelection fixes the deselect-to-zero case while keeping that protection intact.
changed the title [-]Spends - Selection mode does not automatically exit when selection count drops to zero[/-][+][$250] Spends - Selection mode does not automatically exit when selection count drops to zero[/+]on Jun 18, 2026
⚠️@petrovichby Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.
⚠️@petrovichby Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.
⚠️@Pankaj-Sakariya Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.
⚠️@Pankaj-Sakariya Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.
Activity
applause-bot commentedon Jun 18, 2026
While Applause doesn't embed attachments for this bug, here are the links for quick view:
https://platform.applause.com/services/links/v1/external/5fe7fda61f4931a06796e5cf3940899022b6b7660b8481a6817bb2c446075039
MelvinBot commentedon Jun 18, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
On narrow/mobile layout, after long-pressing to enter selection mode and then deselecting rows until the selected count reaches zero, selection mode stays active. It should automatically exit when the selection drops to zero.
What is the root cause of that problem?
The effect that exits mobile selection mode when the selection becomes empty is gated on three conditions, and the third one (
shouldTurnOffSelectionMode) is nevertruefor a manual deselect:src/components/Search/SearchWriteActionsProvider.tsx:282shouldTurnOffSelectionModeis only set totrueby explicit bulk-action clears (clearSelectedTransactions(..., true)— approve/pay/export, etc. atSearchSelectionProvider.tsx:136). Every per-row toggle/deselect instead goes throughapplySelection, which hardcodes the flag tofalseon every commit:src/components/Search/SearchSelectionProvider.tsx:95So when you manually deselect down to zero:
selectedKeys.length === 0✅ andisMobileSelectionModeEnabled✅, butshouldTurnOffSelectionMode === false❌, soturnOffMobileSelectionMode()is never called and selection mode stays on.Note the wide-layout branch already does the right thing — it turns selection mode off on empty with only the two-condition check (no
shouldTurnOffSelectionModegate):SearchWriteActionsProvider.tsx:312-315.What changes do you think we should make in order to solve the problem?
Drop the
shouldTurnOffSelectionModecondition fromuseTurnOffSelectionModeWhenEmptyso it exits selection mode whenever the selection is empty while in mobile selection mode and focused — mirroring the wide-layout branch:Update the effect deps accordingly (drop
shouldTurnOffSelectionMode). After this, theshouldTurnOffSelectionModeflag is still useful for the explicit bulk-action clear path, but it no longer blocks the manual deselect-to-zero case.Investigation details, alternatives & verification note
useTurnOffSelectionModeWhenEmpty, wired in at lines 552-553 of the same file.prepareTransactionsListdeletes the key inselectionBuilders.ts), soselectedTransactionsdoes become{}— the only thing blocking exit is the guard.shouldTurnOffSelectionMode: trueinsideapplySelectionwhen the resulting map is empty. This is more surgical but couples a state-setter to selection-mode UX and risks the flag lingeringtrueinto the next render; removing the guard (matching the already-correct wide-layout branch) is simpler and more consistent.Next Steps for Contributor+ team:
To accept:
@MelvinBot implement [this](https://github.com/Expensify/App/issues/93911)to create a draft PR.To refine:
@MelvinBot <your feedback>To reject: Explain why you are rejecting Melvin's proposal.
MobileMage commentedon Jun 18, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
On a small-screen / mobile search view (the "Spends" list), long-pressing a row enters mobile selection mode. When the user then deselects rows one-by-one until the selection count reaches zero, selection mode stays active instead of automatically exiting. The expectation (and the behavior of every other selectable list in the app) is that emptying the selection by hand should drop the user back out of selection mode.
What is the root cause of that problem?
The Spends list renders through
<Search>, which mountsSearchWriteActionsProvider. That provider owns the two effects that drive mobile selection mode. The one responsible for turning the mode off when the selection empties isuseTurnOffSelectionModeWhenEmpty, and it only firesturnOffMobileSelectionMode()when an extra flag,shouldTurnOffSelectionMode, is alsotrue:App/src/components/Search/SearchWriteActionsProvider.tsx
Lines 281 to 284 in e5928ed
The problem is that
shouldTurnOffSelectionModeis nevertrueon the manual-deselect path. Deselecting a row goes throughtoggle→applySelection, and every commit inapplySelectionhard-resets the flag back tofalse:App/src/components/Search/SearchSelectionProvider.tsx
Lines 90 to 96 in e5928ed
The only thing that sets
shouldTurnOffSelectionMode: trueisclearSelectedTransactions(..., true), and every caller of that is a bulk-action completion path — submitting a hold/reject reason, export, change-report, edit-multiple, etc. (useSelectedTransactionsActions,useExportActions,useSearchBulkActions,SearchHoldReasonPage...). In other words, this flag exists to wipe the selection and leave selection mode after an action runs; it was never meant to cover "the user emptied the selection themselves." So when the last checkbox is unticked, the effect re-runs (its deps includeselectedTransactions), seesselectedKeys.length === 0, butshouldTurnOffSelectionModeis alreadyfalse, and the mode is left on.The sibling effect
useSyncMobileSelectionModeWithScreenSizedoes not save us either: on the small-screen path it only ever turns the mode on, and its only zero-countturnOffMobileSelectionMode()is gated behind!isSmallScreenWidth. Its dependency array is[isSmallScreenWidth]only, so it deliberately never re-runs on selection changes.App/src/components/Search/SearchWriteActionsProvider.tsx
Lines 311 to 324 in e5928ed
The net effect is that the Search write-side has no effect that mirrors the app-wide convention. Every other selectable list uses
useHandleSelectionMode, which callsturnOffMobileSelectionMode()wheneverselectedItems.length === 0with no extra flag gate (only awasSelectionOnRefguard so it doesn't fire on first entry). That hook is exactly whatSelectionListWithModalwires up, and it is the behavior QA is comparing against.What changes do you think we should make in order to solve the problem?
Make
useTurnOffSelectionModeWhenEmptyexit selection mode when the selection empties on the small-screen path, regardless ofshouldTurnOffSelectionMode. TheshouldTurnOffSelectionModebranch should stay (it still serves the post-bulk-action "clear + exit" case where the selection is wiped programmatically), but we add the manual-deselect case alongside it so the effect matches theuseHandleSelectionModeconvention. Concretely, inSearchWriteActionsProvider.tsx, passisSmallScreenWidthinto the hook and broaden the condition:This is safe because the body only runs after the screen is focused (the early
isFocusedreturn is kept) and only when nothing is selected and the mode is currently on — so it can't interfere with an in-flight reconcile (which leaves at least one key) or with entering selection mode (which always selects the long-pressed row first inturnOnSelectionMode, soselectedKeysis never empty at entry). It also doesn't disturb the wide-screen behavior, which is already handled byuseSyncMobileSelectionModeWithScreenSize. Restricting the new branch toisSmallScreenWidthkeeps the change scoped to the platform where mobile selection mode actually exists, and the effect already re-runs onselectedTransactionschanges so the exit happens the moment the count hits zero.What alternative solutions did you explore? (Optional)
I considered replacing the whole custom pair of Search effects with the shared
useHandleSelectionMode(selectedKeys)hook for consistency, but the Search write-side intentionally keepsshouldTurnOffSelectionModeand the reconcile-aware select-all logic thatuseHandleSelectionModedoesn't know about, so swapping wholesale risks regressing the bulk-action and select-all flows; the targeted condition change keeps those intact while restoring the expected exit-at-zero behavior.ahmdshrif commentedon Jun 18, 2026
🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.
lorretheboy commentedon Jun 18, 2026
🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.
melvin-bot commentedon Jun 18, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @aimane-chnaif (
External)wildan-m commentedon Jun 18, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
On the Spends page (and other Search list views), after long-pressing a row to enter mobile selection mode and then deselecting rows until the selection count drops to zero, selection mode stays active. It should automatically exit once nothing is selected.
What is the root cause of that problem?
The Search selection feature has a dedicated effect whose job is exactly this — turn mobile selection mode off once nothing is selected:
App/src/components/Search/SearchWriteActionsProvider.tsx
Lines 273 to 289 in 3b90c4c
But it only fires when the
shouldTurnOffSelectionModeflag istrue:App/src/components/Search/SearchWriteActionsProvider.tsx
Line 282 in 3b90c4c
That flag is committed to selection state in
applySelection, which is the write path every row/checkbox toggle (including deselection) goes through.applySelectionhardcodes the flag tofalseon every commit:App/src/components/Search/SearchSelectionProvider.tsx
Lines 79 to 99 in 3b90c4c
So when the user manually deselects rows down to zero,
applySelectionresetsshouldTurnOffSelectionModetofalse, and the turn-off effect never runs. The flag is only ever set totruebyclearSelectedTransactions(..., true), which is called after bulk actions (reject/hold/edit-multiple) complete — i.e. only a programmatic clear can currently exit selection mode, not a manual deselect-to-zero.What changes do you think we should make in order to solve the problem?
In
applySelection(insrc/components/Search/SearchSelectionProvider.tsx), instead of hardcodingshouldTurnOffSelectionMode: falsein the committed state, derive it from whether the resulting selection is empty — set it totruewhen the newselectedTransactionsmap is empty andfalseotherwise.isEmptyObjectis already imported in this file, so the value becomesisEmptyObject(selectedTransactions)(using the updated map computed a few lines above).App/src/components/Search/SearchSelectionProvider.tsx
Lines 79 to 99 in 3b90c4c
With this change, when a toggle deselects the last selected row, the committed selection is empty,
shouldTurnOffSelectionModebecomestrue, and the existinguseTurnOffSelectionModeWhenEmptyeffect fires and exits mobile selection mode — matching the expected behavior.This also preserves the guard that protects entry into selection mode: long-pressing a row turns selection mode on and immediately toggles the long-pressed item, so the committed selection is non-empty and the flag stays
false— the mode is not turned off the instant it is turned on.Compare branch: https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/93911-exit-selection-mode-on-deselect-to-zero?expand=1
What alternative solutions did you explore? (Optional)
Removing the
&& shouldTurnOffSelectionModecondition from the turn-off effect so it fires whenever the selection is empty. This was rejected because that flag also guards the entry race: when selection mode is turned on, there can be a render where mobile selection mode is enabled but the selection map is still empty (before the long-pressed item's toggle commits). Without the flag, the effect would immediately turn selection mode back off. Driving the flag from the committed selection's emptiness inapplySelectionfixes the deselect-to-zero case while keeping that protection intact.[-]Spends - Selection mode does not automatically exit when selection count drops to zero[/-][+][$250] Spends - Selection mode does not automatically exit when selection count drops to zero[/+]melvin-bot commentedon Jun 18, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022067485044239118010
20 remaining items
github-actions commentedon Jun 19, 2026
github-actions commentedon Jun 19, 2026
FitseTLT commentedon Jun 19, 2026
I think this is expected cc @Expensify/product
shawnborton commentedon Jun 20, 2026
cc @Expensify/design too but I do think this is expected.
Pankaj-Sakariya commentedon Jun 20, 2026
🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.
github-actions commentedon Jun 20, 2026
Pankaj-Sakariya commentedon Jun 20, 2026
🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.
github-actions commentedon Jun 20, 2026
dannymcclain commentedon Jun 22, 2026
Agree - this is expected/desired behavior.
shawnborton commentedon Jun 22, 2026
Okay cool, I think we can close then.
aimane-chnaif commentedon Jun 22, 2026
Let's close this