Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HOLD for payment 2023-06-29] [$1000] Arrow key shortcut stops working #19700

Closed
1 of 6 tasks
aldo-expensify opened this issue May 26, 2023 · 44 comments
Closed
1 of 6 tasks
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering External Added to denote the issue can be worked on by a contributor

Comments

@aldo-expensify
Copy link
Contributor

aldo-expensify commented May 26, 2023

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Coming from: https://github.com/Expensify/App/pull/18883/files#r1206010822

Action Performed:

  1. Open the panel to invite new members to a workspace (/workspace//invite)
  2. Verify that arrows up and down work and they change the selected row
  3. Select something with the mouse
  4. Click Next
  5. Go back
  6. BUG: The arrow keys don't change the highlighted row anymore

Expected Result:

Pressing UP or DOWN should change the highlighted row

Actual Result:

Pressing UP or DOWN doesn't do anything

Workaround:

Can the user still use Expensify without this being fixed? Have you informed them of the workaround?

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number:
Reproducible in staging?:
Reproducible in production?:
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation
Expensify/Expensify Issue URL:
Issue reported by:
Slack conversation:

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01ecaf4548dae58200
  • Upwork Job ID: 1668438254258597888
  • Last Price Increase: 2023-06-13
@aldo-expensify aldo-expensify added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels May 26, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 26, 2023

Triggered auto assignment to @johncschuster (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot
Copy link

melvin-bot bot commented May 26, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@aldo-expensify
Copy link
Contributor Author

The cause is pretty narrowed down here:

I think this would have been easier to fix if we were dealing with functional components. There out of the box memoization with Class components. The recommended way is to use the library memoize-one which we don't currently have, and I'm not sure we want it since we are moving toward functional components.

@johncschuster
Copy link
Contributor

FYI - No Slack thread for this one.

@melvin-bot
Copy link

melvin-bot bot commented May 30, 2023

Triggered auto assignment to @flodnv (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

@flodnv
Copy link
Contributor

flodnv commented May 30, 2023

From @aldo-expensify's investigation it seems like @roryabraham you caused this in #18883, can you have a look please and let us know what you think?

@flodnv flodnv assigned roryabraham and unassigned flodnv May 30, 2023
@aldo-expensify
Copy link
Contributor Author

Also, Vit was recommending me to get help from one of our external expert agencies to work on this (here). I think that could be a good idea.

@roryabraham
Copy link
Contributor

Looking into this now

@melvin-bot melvin-bot bot removed the Overdue label Jun 1, 2023
@roryabraham
Copy link
Contributor

I'm not sure I yet see how this is related to #18883, because the OptionsSelector doesn't yet use the useArrowKeyFocusManager or useKeyboardShortcut hooks.

@roryabraham
Copy link
Contributor

Found this lib which honestly seems pretty slick

@aldo-expensify
Copy link
Contributor Author

aldo-expensify commented Jun 1, 2023

  • PopoverMenu subscribe shortcuts globally using useArrowKeyFocusManager and useKeyboardShortcut
  • BaseOptionsSelector subscribes globally ARROW UP and ARROW DOWN keys using ArrowKeyFocusManager (here)
  • In the past, PopoverMenu subscribed shortcuts before BaseOptionsSelector's subscribed shortcuts, just because of mounting order. This made the BaseOptionsSelector's callback execute first.
  • Since the change introduced by Pay Header improvements #18883, PopoverMenu is constantly unsubscribing and subscribing the shortcuts, moving the callback to the front of any other with the same priority thanks to the way we insert the callback here (slice).
  • When the callback subscribed by PopoverMenu executes first, it doesn't give a chance to BaseOptionsSelector's callback to execute because it prevents bubbling shouldBubble = false (default here)

I'm pretty sure you could fix this particular bug by playing with the priorities during subscribe, but I still think this should be fix in a way it stops unsubscribing/subscribing every cycle.

@aldo-expensify
Copy link
Contributor Author

Found this lib which honestly seems pretty slick

Interesting, the focus trap thing could help solving the problem we have with key event listeners that keep listening even out of view (see https://expensify.slack.com/archives/C01GTK53T8Q/p1685138015892469 / #18419)

@roryabraham
Copy link
Contributor

This seems like the exact scenario the upcoming React.useEvent hook is designed for.

@aldo-expensify
Copy link
Contributor Author

This seems like the exact scenario the upcoming React.useEvent hook is designed for.

In only found this: reactjs/rfcs#220

Is this going to be implemented? Looks good, but I think for the moment, if that is not near to be released, this can be done with useCallback + useMemo in functional react. In class components is hard I believe.

@roryabraham
Copy link
Contributor

Yeah, it's just an RFC now, and we should be able to simulate it.

@roryabraham
Copy link
Contributor

Put up a draft PR with a potential fix: #20016. More testing and discussion is needed since it uses an experimental React feature which is explained in good detail here: https://react.dev/learn/separating-events-from-effects#declaring-an-event-function

@melvin-bot
Copy link

melvin-bot bot commented Jun 13, 2023

📣 @gedu You have been assigned to this job by @roryabraham!
Please apply to this job in Upwork and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@Santhosh-Sellavel
Copy link
Collaborator

I'll just wait for the PR then, thanks for the early review @roryabraham!

@gedu
Copy link
Contributor

gedu commented Jun 14, 2023

@roryabraham @aldo-expensify Hey, while I was adding the isActive and doing the cleanup, I noticed that the useArrowKeyFocusManager function has an unstable type for the disabledIndexes parameter, which is disabledIndexes = []. This causes any hook that uses this parameter to be recreated every time.

I was improving the callback for useKeyboardShortcut so the useEffect doesn't get called everytime. but if I do this

 const arrowUpCallback = useCallback(() => {
        if (maxIndex < 0) {
            return;
        }

        setFocusedIndex((index) => {
            const currentFocusedIndex = index > 0 ? index - 1 : maxIndex;
            let newFocusedIndex = currentFocusedIndex;

            while (disabledIndexes.includes(newFocusedIndex)) {
                newFocusedIndex = newFocusedIndex > 0 ? newFocusedIndex - 1 : maxIndex;
                if (newFocusedIndex === currentFocusedIndex) {
                    // all indexes are disabled
                    return index; // no-op
                }
            }
            return newFocusedIndex;
        });
    }, [disabledIndexes, maxIndex]);
    useKeyboardShortcut(CONST.KEYBOARD_SHORTCUTS.ARROW_UP, arrowUpCallback, arrowConfig);
    ```
    because `disabledIndexes` always is a new array the function will be recreating calling again the `useEffect`, chatting internally I think the best option is to create a const array and use it, in this case, is good because we just query the value, doing this we avoid that when other use this hook they don't need to use `useMemo` and pass always an array.
    
    ```
    const EMPTY_ARRAY = Object.freeze([]);
    
    function useArrowKeyFocusManager({
    maxIndex,
    onFocusedIndexChange = () => {},
    initialFocusedIndex = 0,
    disabledIndexes = EMPTY_ARRAY,
    shouldExcludeTextAreaNodes = true,
    isActive,
}) {}

Doing freeze so if someone tries to mutate the array get an error, because at least for now we don't want to support that behavior.

I want to point this out because as we start using hooks, these issues could arise in many places.

What do you think?

Before
Screen Shot 2023-06-14 at 15 37 46

After
Screen Shot 2023-06-14 at 15 38 13

@melvin-bot melvin-bot bot added the Reviewing Has a PR in review label Jun 15, 2023
@chrispader
Copy link
Contributor

The isActive addition would also come in handy in this PR, since we want to be able to use the useArrowKeyFocusManager for two different contexts (emojis and suggestions), and being able to disable a keyboard shortcut subscription temporarily, would be great

@melvin-bot
Copy link

melvin-bot bot commented Jun 19, 2023

Based on my calculations, the pull request did not get merged within 3 working days of assignment. Please, check out my computations here:

  • when @gedu got assigned: 2023-06-13 18:12:11 Z
  • when the PR got merged: 2023-06-19 16:37:20 UTC
  • days elapsed: 4

On to the next one 🚀

@gedu gedu mentioned this issue Jun 20, 2023
67 tasks
@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Daily KSv2 labels Jun 22, 2023
@melvin-bot melvin-bot bot changed the title [$1000] Arrow key shortcut stops working [HOLD for payment 2023-06-29] [$1000] Arrow key shortcut stops working Jun 22, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Jun 22, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jun 22, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Jun 22, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.30-5 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 2023-06-29. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter - Internal
  • Contributor that fixed the issue - @gedu
  • Contributor+ that helped on the issue and/or PR - @Santhosh-Sellavel

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented Jun 22, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@Santhosh-Sellavel] The PR that introduced the bug has been identified. Link to the PR:
  • [@Santhosh-Sellavel] 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:
  • [@Santhosh-Sellavel] A discussion in #expensify-bugs 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:
  • [@Santhosh-Sellavel] Determine if we should create a regression test for this bug.
  • [@Santhosh-Sellavel] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@johncschuster] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Jun 28, 2023
@roryabraham
Copy link
Contributor

I think this is ready for payment now

@Santhosh-Sellavel
Copy link
Collaborator

Santhosh-Sellavel commented Jul 2, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

@Santhosh-Sellavel
Copy link
Collaborator

Santhosh-Sellavel commented Jul 2, 2023

Bug: Arrow key selection stops working on the workspace invite members page

Regression Steps

  1. Open the panel to invite new members to a workspace (/workspace//invite)
  2. Verify that arrows up and down work and the selected row is changed
  3. Select something with the mouse
  4. Click Next
  5. Go back
  6. The arrow keys change the highlighted row

👍 or 👎

cc: @roryabraham @johncschuster

@melvin-bot melvin-bot bot added the Overdue label Jul 5, 2023
@johncschuster
Copy link
Contributor

@Santhosh-Sellavel Upwork invite sent. Can you please ping me when you've accepted?

@melvin-bot melvin-bot bot removed the Overdue label Jul 6, 2023
@johncschuster
Copy link
Contributor

@Santhosh-Sellavel has requested payment via NewDot 🎉

@anmurali
Copy link

anmurali commented Jul 7, 2023

Paid

@johncschuster
Copy link
Contributor

Thanks, @anmurali!

@roryabraham
Copy link
Contributor

Then, since @gedu works for Callstack, we are all set to close this 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

8 participants