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
[HOLD for payment 2025-11-04] [$250] Ensure the focus in the chat switcher does not change when the API results get in #71777
1. CMD+K to open the chat switcher
1. Type a few letters
1. Hit arrow down to go to the 3rd result
1. Go to press enter to switch to 3rd result
1. API request completes
1. Focus jumps to 1st result, and I press enter on the 1st result by mistake
Solution
Make sure to keep the focus on the row that the user switched to, even after the API results populate. That means the content of the option row can change, but if you clicked down to third row, you will remain on third row
changed the title [-]Ensure the focus in the chat switcher does not change when the API results get in[/-][+][$250] Ensure the focus in the chat switcher does not change when the API results get in[/+]on Oct 2, 2025
Please re-state the problem that we are trying to solve in this issue.
The chat switcher (Command/Ctrl + K) moves keyboard focus back to the first search result whenever the option list refreshes after an API response. If I arrow down to the third row and the list re-renders, the highlight jumps to row one, so the next Enter opens the wrong chat.
What is the root cause of that problem?
BaseSelectionListWithSections unconditionally calls updateAndScrollToFocusedIndex(0) whenever the option list changes while the search input still has text. That logic lives in the focus-reset effect and ignores whatever index the user already chose, so any data refresh snaps the focus to the first item
// Remove the focus if the search input is empty and prev search input not empty or selected options length is changed (and allOptions length remains the same)
What changes do you think we should make in order to solve the problem?
Keep the current focus index when the list re-renders, only falling back to the first item if the user has never moved the highlight.
Clamp the preserved index when the refreshed list is shorter so we stay on the closest valid row instead of jumping to the top.
Allow the existing "reset to -1" path to run only when the list genuinely needs to drop focus (for example, when the filter text is cleared).
Add focusedIndex to the effect dependencies and skip calling updateAndScrollToFocusedIndex when the next index matches the current one to avoid redundant scrolls.
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
Unit-test BaseSelectionListWithSections so that after moving focus to a non-zero index, re-rendering with the same search text keeps the highlight on that index.
Verify that when the refreshed list shrinks, the focus clamps to the last available row instead of resetting to the top.
Ensure clearing the search text (or otherwise triggering the "remove focus" branch) still drops the highlight as before.
What changes do you think we should make in order to solve the problem?
This was implemented in here to highlight the first item whose text matches the search text. So here to avoid unnecessary confusion if the user has already manually focused on a non-zero index we should skip it.
changed the title [-][$250] Ensure the focus in the chat switcher does not change when the API results get in[/-][+][HOLD for payment 2025-11-04] [$250] Ensure the focus in the chat switcher does not change when the API results get in[/+]on Nov 4, 2025
[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: This isn’t a bug — it looks more like an improvement we hadn’t considered before.
[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:
[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.
Activity
melvin-bot commentedon Oct 2, 2025
Triggered auto assignment to @kadiealexander (
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.[-]Ensure the focus in the chat switcher does not change when the API results get in[/-][+][$250] Ensure the focus in the chat switcher does not change when the API results get in[/+]melvin-bot commentedon Oct 2, 2025
Job added to Upwork: https://www.upwork.com/jobs/~021973752690388910836
melvin-bot commentedon Oct 2, 2025
Triggered auto assignment to Contributor-plus team member for initial proposal review - @DylanDylann (
External)ShridharGoel commentedon Oct 2, 2025
Proposal
Please re-state the problem that we are trying to solve in this issue.
The chat switcher (Command/Ctrl + K) moves keyboard focus back to the first search result whenever the option list refreshes after an API response. If I arrow down to the third row and the list re-renders, the highlight jumps to row one, so the next Enter opens the wrong chat.
What is the root cause of that problem?
BaseSelectionListWithSectionsunconditionally callsupdateAndScrollToFocusedIndex(0)whenever the option list changes while the search input still has text. That logic lives in the focus-reset effect and ignores whatever index the user already chose, so any data refresh snaps the focus to the first itemApp/src/components/SelectionListWithSections/BaseSelectionListWithSections.tsx
Lines 827 to 858 in faea12d
What changes do you think we should make in order to solve the problem?
focusedIndexto the effect dependencies and skip callingupdateAndScrollToFocusedIndexwhen the next index matches the current one to avoid redundant scrolls.What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
BaseSelectionListWithSectionsso that after moving focus to a non-zero index, re-rendering with the same search text keeps the highlight on that index.FitseTLT commentedon Oct 2, 2025
🚨 Edited by proposal-police: This proposal was edited at 2025-10-02 17:26:02 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Ensure the focus in the chat switcher does not change when the API results get in
What is the root cause of that problem?
We have a logic to focus on the first result if its
textmatches the search text hereApp/src/components/Search/SearchAutocompleteList.tsx
Lines 777 to 783 in 3262b4b
What changes do you think we should make in order to solve the problem?
This was implemented in here to highlight the first item whose
textmatches the search text. So here to avoid unnecessary confusion if the user has already manually focused on a non-zero index we should skip it.App/src/components/SelectionListWithSections/BaseSelectionListWithSections.tsx
Lines 783 to 788 in 3262b4b
App/src/components/Search/SearchRouter/SearchRouter.tsx
Line 521 in 3262b4b
Additionally we can remove onHighlightFirstItem from dependency here
App/src/components/Search/SearchAutocompleteList.tsx
Line 783 in 3262b4b
or pass memoized callback here
App/src/components/Search/SearchRouter/SearchRouter.tsx
Line 521 in 3262b4b
because currently the effect is running even if the first result text hasn't changed (normalizedReferenceText)
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
N / A
What alternative solutions did you explore? (Optional)
M00rish commentedon Oct 3, 2025
🚨 Edited by proposal-police: This proposal was edited at 2025-10-03 02:07:47 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Ensure the focus in the chat switcher does not change when the API results get in
What is the root cause of that problem?
new behavior
What changes do you think we should make in order to solve the problem?
when switching focus with arrows:
App/src/components/SelectionListWithSections/BaseSelectionListWithSections.tsx
Lines 427 to 436 in 0605e4f
we can preserve the focused index :
and in
updateAndScrollToFocusedIndex:and we could introduce a new argument for
updateAndScrollToFocusedIndexwhen we wantfocusedItemKeyRefto be ignored and focus normallyWhat specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
N/A
What alternative solutions did you explore? (Optional)
N/A
31 remaining items
melvin-bot commentedon Nov 4, 2025
Triggered auto assignment to @sonialiap (
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.[-][$250] Ensure the focus in the chat switcher does not change when the API results get in[/-][+][HOLD for payment 2025-11-04] [$250] Ensure the focus in the chat switcher does not change when the API results get in[/+]mountiny commentedon Nov 4, 2025
$250 to @FitseTLT and @DylanDylann
mallenexpensify commentedon Nov 5, 2025
Payment Summary
Contributor: @FitseTLT paid $250 via Upwork
Contributor+: @DylanDylann due $250 via NewDot
@DylanDylann plz complete the BZ checklist.
DylanDylann commentedon Nov 5, 2025
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: This isn’t a bug — it looks more like an improvement we hadn’t considered before.
[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:
[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/565231
Regression Test Proposal
Test:
Note: this should be tested only on Web (mac) and Desktop platforms
Do we agree 👍 or 👎
sonialiap commentedon Nov 5, 2025
Looks like Matt made the payment in Upwork so I'm closing this out
trjExpensify commentedon Dec 5, 2025
approved $250 for @DylanDylann