Skip to content

[Due for payment 2025-04-25] [$250] Web- Search - Top-most result in Recent chats is not highlighted #59552

Closed

Description

@vincdargento

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.1.22-5
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: N/A
If this was caught during regression testing, add the test name, ID and link from TestRail: https://github.com/Expensify/Expensify/issues/452028
Email or phone of affected tester (no customers): N/A
Issue reported by: Applause Internal Team
Device used: Windows 10 chrome
App Component: Search

Action Performed:

  1. Go to https://staging.new.expensify.com/home
  2. Log in to a account
  3. Tap search icon

Note: The first recent chat is not highlighted only on the first try after signing in, it is highlighted on the second try

Expected Result:

Top-most result in Recent chats is highlighted

Actual Result:

Top-most result in Recent chats is not highlighted

Workaround:

Unknown

Platforms:

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

bug.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021907790385956529885
  • Upwork Job ID: 1907790385956529885
  • Last Price Increase: 2025-04-03
  • Automatic offers:
    • FitseTLT | Contributor | 106778897
Issue OwnerCurrent Issue Owner: @NicMendonca

Activity

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

    @melvin-bot

    Triggered auto assignment to @NicMendonca (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. ChavdaSachin commented on Apr 2, 2025

    @ChavdaSachin
    Contributor

    Unable to repro.

  4. thelullabyy commented on Apr 2, 2025

    @thelullabyy
    Contributor

    Proposal

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

    Top-most result in Recent chats is not highlighted

    What is the root cause of that problem?

    The first time the search bar is turned on, data from recentReportsOptions that has not been loaded will return empty. So styledRecentReports is empty, styledRecentReports.at(0)?.keyForList return undefined, thus the first recent chat is not highlighted.

    initiallyFocusedOptionKey={!shouldUseNarrowLayout ? styledRecentReports.at(0)?.keyForList : undefined}

    Inside useArrowKeyFocusManager, initialFocusedIndex is only used in the initial state setup with useState, and subsequent changes to initiallyFocusedOptionKey don't trigger a state update.

    const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({
    initialFocusedIndex: flattenedSections.allOptions.findIndex((option) => option.keyForList === initiallyFocusedOptionKey),

    const [focusedIndex, setFocusedIndex] = useState(initialFocusedIndex);

    When recentReportsOptions is loaded, SelectionList still retains the state of the original initiallyFocusedOptionKey

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

    Add a useEffect to watch for changes in initiallyFocusedOptionKey inside BaseSelectionList

    function BaseSelectionList<TItem extends ListItem>(

    useEffect(() => {
            const newIndex = flattenedSections.allOptions.findIndex(
                (option) => option.keyForList === initiallyFocusedOptionKey
            );
            setFocusedIndex(newIndex);
        }, [initiallyFocusedOptionKey, flattenedSections.allOptions]);
    

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    NA

    What alternative solutions did you explore? (Optional)

    Use a key prop to force a complete re-render of the component when initiallyFocusedOptionKey changes

    <SelectionList<OptionData | SearchQueryItem>
    sections={sections}

    key={styledRecentReports.at(0)?.keyForList}

    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. samranahm commented on Apr 2, 2025

    @samranahm
    Contributor

    Unable to repro.

    @ChavdaSachin can you share a quick video so that we get to know this is regression from PR

  6. samranahm commented on Apr 2, 2025

    @samranahm
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2025-04-03 15:36:34 UTC.

    Proposal

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

    What is the root cause of that problem?

    Here

    // If `initiallyFocusedOptionKey` is not passed, we fall back to `-1`, to avoid showing the highlight on the first member
    const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({
    initialFocusedIndex: flattenedSections.allOptions.findIndex((option) => option.keyForList === initiallyFocusedOptionKey),

    useArrowKeyFocusManager initializes immediately with:

    initialFocusedIndex: flattenedSections.allOptions.findIndex(...)

    But flattenedSections.allOptions empty during first render (when we first open the search router)

    • It returns -1 even when initiallyFocusedOptionKey exists
    • Once it set to -1, there is currently no logic to "retry" focusing when options loaded

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

    We should add useEffect bellow this useEffect

    useEffect(() => {
    if (selectedItemIndex === -1 || selectedItemIndex === focusedIndex || textInputValue) {
    return;
    }
    setFocusedIndex(selectedItemIndex);
    // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
    }, [selectedItemIndex]);

    that runs after options are loaded

    useEffect(() => {
        if (flattenedSections.allOptions.length > 0 && initiallyFocusedOptionKey && focusedIndex === -1) {
            const index = flattenedSections.allOptions.findIndex((option) => option.keyForList === initiallyFocusedOptionKey);
            if (index !== -1) {
                setFocusedIndex(index);
            }
        }
    }, [flattenedSections.allOptions, initiallyFocusedOptionKey, focusedIndex]);

    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)

    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.

  7. NicMendonca commented on Apr 3, 2025

    @NicMendonca
    Contributor
    Image

    Then after a refresh:

    Image
  8. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Apr 3, 2025
  9. changed the title [-]Web- Search - Top-most result in Recent chats is not highlighted[/-] [+][$250] Web- Search - Top-most result in Recent chats is not highlighted[/+] on Apr 3, 2025
  10. melvin-bot commented on Apr 3, 2025

    @melvin-bot
  11. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Apr 3, 2025
  12. 19 remaining items

  13. melvin-bot commented on Apr 18, 2025

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  14. melvin-bot commented on Apr 18, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.29-10 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2025-04-25. 🎊

    For reference, here are some details about the assignees on this issue:

  15. melvin-bot commented on Apr 18, 2025

    @melvin-bot

    @shubham1206agra @NicMendonca @shubham1206agra The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  16. NicMendonca commented on Apr 25, 2025

    @NicMendonca
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [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:

    • [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.

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

      Link to issue:

    Regression Test Proposal

    Precondition:

    Test:

    Do we agree 👍 or 👎

  17. NicMendonca commented on Apr 25, 2025

    @NicMendonca
    Contributor

    Payment summary

  18. shubham1206agra commented on Apr 25, 2025

    @shubham1206agra
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [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: https://github.com/Expensify/App/pull/53198/files#r2060452367

    • [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: Not Required

    • [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:

    Regression Test Proposal

    Test:

    1. Open the app or refresh the page on web
    2. Tap the search icon
    3. Verify that the first recent chat is highlighted for large screens (web and desktop only, not for mobile)

    Do we agree 👍 or 👎

  19. NicMendonca commented on Apr 28, 2025

    @NicMendonca
    Contributor
  20. garrettmknight commented on May 13, 2025

    @garrettmknight
    Contributor

    $250 approved for @shubham1206agra

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