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-09-12] [$1000] Compose Box - User able to select 2 emoji at a time #24261

Closed
1 of 6 tasks
lanitochka17 opened this issue Aug 8, 2023 · 60 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 External Added to denote the issue can be worked on by a contributor

Comments

@lanitochka17
Copy link

lanitochka17 commented Aug 8, 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!


Action Performed:

  1. Launch app
  2. Tap on a report
  3. Tap on emoji picker in compose box
  4. From smileys&emotion section, select any 2 emoji

Expected Result:

The user should be able to select only one emoji at a time

Actual Result:

The user is allowed to select 2 emojis at a time

Workaround:

Unknown

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: 1.3.51.0

Reproducible in staging?: Yes

Reproducible in production?: Yes

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

Bug6157001_twoemojiusethis.mp4

Expensify/Expensify Issue URL:

Issue reported by: Applause - Internal Team

Slack conversation:

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01d67b0c351a8b8c5d
  • Upwork Job ID: 1689041921265803264
  • Last Price Increase: 2023-08-08
  • Automatic offers:
    • tienifr | Contributor | 26144133
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Aug 8, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 8, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Aug 8, 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

@akinwale
Copy link
Contributor

akinwale commented Aug 8, 2023

Proposal

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

A user is able to select and send 2 emojis at the same time before the emoji picker closes.

What is the root cause of that problem?

After the user selects an emoji, the other emojis can still accept touch or press input during the brief period while the emoji picker is still open. Since the other emojis can still accept touch or press input, the onPress event handler will be invoked for any subsequent emoji pressed. Note that this only happens on iOS and Android native.

onPress={(emoji) => addToFrequentAndSelectEmoji(emoji, item)}

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

Since this happens on iOS and Android native (all web platforms and desktop are fine), only EmojiPickerMenu/index.native.js needs to be updated.

Solution 1
Use a reference to store a flag that an emoji has already been pressed. The following changes can be made to achieve this:

  1. Add the useRef: const emojiPickedRef = useRef(null);
  2. Update the onPress handler:
onPress={(emoji) => {
    if (emojiPickedRef.current) {
        return;
    }
    emojiPickedRef.current = true;
    addToFrequentAndSelectEmoji(emoji, item);
}}

Solution 2
Debounce (combined with useCallback if necessary), or throttle the onPress handler for the emoji picker item in the EmojiPickerMenu component.

What alternative solutions did you explore? (Optional)

I tried to use a state variable to track the emoji picked boolean flag, but it is possible for a user to tap fast enough to send a subsequent onPress event before React updates the state.

@lschurr lschurr added the External Added to denote the issue can be worked on by a contributor label Aug 8, 2023
@melvin-bot melvin-bot bot changed the title Compose Box - User able to select 2 emoji at a time [$1000] Compose Box - User able to select 2 emoji at a time Aug 8, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 8, 2023

Job added to Upwork: https://www.upwork.com/jobs/~01d67b0c351a8b8c5d

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 8, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 8, 2023

Current assignee @lschurr is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Aug 8, 2023

Triggered auto assignment to Contributor-plus team member for initial proposal review - @robertKozik (External)

@FabianKoder
Copy link

FabianKoder commented Aug 9, 2023

Proposal

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

A user is able to select 2 emojis at the same time before the emoji picker closes.

What is the root cause of that problem?

const addToFrequentAndSelectEmoji = (emoji, emojiObject) => {
const frequentEmojiList = EmojiUtils.getFrequentlyUsedEmojis(emojiObject);
User.updateFrequentlyUsedEmojis(frequentEmojiList);
onEmojiSelected(emoji, emojiObject);
};

The onEmojiSelected call toggles the visibility of the emoji picker, but since it it a state, it only will be updated on the next render (when the emoji picker disappears).

It is also possible to add more than 2 emojis if the device is slow enough.

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

if (!isEmojiPickerVisible) {

Check if emojiPopoverAnchor.current is null, instead of checking if !isEmojiPickerVisibile. This will ensure that even before the next render, the selectEmoji function will know that it needs to prevent adding another emoji. This would also solve the bug if it would occur on web (which probably just not occurs because the state update happens faster, e.g. because of faster devices).

What alternative solutions did you explore? (Optional)

N/A

Note: I edited this proposal, since my first proposal was not tested. The new one is tested and confirmed that it works.

@tienifr
Copy link
Contributor

tienifr commented Aug 9, 2023

Proposal

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

The user is allowed to select 2 emojis at a time.

What is the root cause of that problem?

In here

onPress={(emoji) => addToFrequentAndSelectEmoji(emoji, item)}
, if we press emojis quickly, the onPress will be triggered multiple times, causing many emojis to be selected.

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

We need to prevent selection of emojis if the last emoji selection didn't finish executing. After this issue is fixed, we'll have a useSingleExecution hook that can be used to limit execution to one at a time (see detailed explanation here).

Then we can use that hook to wrap the callback here

onPress={(emoji) => addToFrequentAndSelectEmoji(emoji, item)}
, so we can ensure the emoji can only be selected one at a time.

There'll be small changes needed in that useSingleExecution definition to allow passing in params

(action) => (...params) => {

and

const execution = action(params);

Then it will be a 1-liner change in here:

onPress={singleExecution((emoji) => addToFrequentAndSelectEmoji(emoji, item))}

and it uses a general approach that's also used in other places in the app (useSingleExecution).

What alternative solutions did you explore? (Optional)

NA

@jeet-dhandha
Copy link
Contributor

Proposal

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

  • Two emoji's can be selected on android when fast selecting emoji's.

What is the root cause of that problem?

  • The addToFrequentAndSelectEmoji method is not debounced or handled in any way to prevent fast selecting emoji's.

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

I have three solutions:

  1. Debounce the addToFrequentAndSelectEmoji method using _.debounce from lodash.
  2. Using ref to check if the emoji is already selected.
  3. Calling InteractionManager.runAfterInteractions to prevent fast selecting emoji's.

What alternative solutions did you explore? (Optional)

  • N/A

@gzqyl
Copy link

gzqyl commented Aug 10, 2023

Proposal
Please re-state the problem that we are trying to solve in this issue.
A user is able to select and send 2 emojis at the same time before the emoji picker closes.

What is the root cause of that problem?
before the component become invisible, the user has clicked more than once, then the function selectEmoji execute twice or more, just depends on component visibility states not the best solution, and that is why the user now could still select two emoji if he clicks very fast.

[App/src/components/EmojiPicker/EmojiPicker.js]

Line 98

if (!isEmojiPickerVisible) { return; }

What changes do you think we should make in order to solve the problem?
I have found a very simple while effective way to solve such problems.

Solution video demo, I tested it on android, it works fine, after the user click the emoji, the modal hides then, and the user has no way to select two or more emoji at one time.

demo

If I have been chosen, kindly let me know, the project is great, I see only Android is checked, if it requires all platform demo, I will upload the demos later, and PR later.

Contributor details
Your Expensify account email: allen.gzqyl@gmail.com
Upwork Profile Link: https://www.upwork.com/freelancers/~01e99782a01937e92c

@melvin-bot melvin-bot bot added the Overdue label Aug 10, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 10, 2023

📣 @gzqyl! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:

  1. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  2. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  3. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
    Screen Shot 2022-11-16 at 4 42 54 PM
    Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

@gzqyl
Copy link

gzqyl commented Aug 10, 2023

Contributor details
Expensify account email: allen.gzqyl@gmail.com
Upwork Profile Link: https://www.upwork.com/freelancers/~01e99782a01937e92c
Just for confirmation, if it duplicates, ignore it, thanks.
just find that @foxmail.com can not be added slack channel, so I use google mail as a replace.

@lschurr
Copy link
Contributor

lschurr commented Aug 10, 2023

@robertKozik could you review these proposals?

@melvin-bot melvin-bot bot removed the Overdue label Aug 10, 2023
@lschurr
Copy link
Contributor

lschurr commented Aug 11, 2023

@robertKozik
Copy link
Contributor

Thank you all for your proposals! 🙇🏼

@jeet-dhandha - using debounce is almost the same as setTimeout usage. So in case we have other possible solutions it's better to not use it. The other approaches you include in your proposal, were already posted by other users (using ref by @akinwale & @Fabb111)

@gzqyl - Your proposal lacks explanation of the solution. I cannot tell from your comment whether or not your solution is better/worst than others as you just include the video of the working solution

@akinwale & @Fabb111 both your solutions are quite similar - they're just using the different refs to detect whether or not modal will be soon closed. But even though this approach would be successful I believe that it's not tackling the root cause directly - which is that user can click multiple times before modal close. We are just ensuring that only the first would be handled (I'm aware that it means exactly the same as prohibiting multiple clicks, but the approach suggested by @tienifr will be the better option, as it can be used in multiple places and standardise the approach to such a cases across the app)

@tienifr implementing and standardising on one function for prohibiting multiple function calls is the way to go in my opinion. It tackles the problem at it roots removing to call function multiple times

This said I believe that proposal from @tienifr is the way to go here, so we would have the same approach (useSingleExecution hook) used across the app.

Selected Proposal: Proposal
Author of Proposal: @tienifr

🎀 👀 🎀 C+ reviewed

@melvin-bot
Copy link

melvin-bot bot commented Aug 11, 2023

Triggered auto assignment to @marcochavezf, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@jeet-dhandha
Copy link
Contributor

Okay @robertKozik. Keep up the Good Work @tienifr 🥂.

@gzqyl
Copy link

gzqyl commented Aug 11, 2023

@robertKozik the solution chosen looks very good, while I had tested it just now, it seems the bug still occurs, I understand that the video I uploaded is a little hard to check whether it works or not, as when the user clicks slower, the bug will not occur.
After use the hook "useSingleExecution", sometimes it is ok, while sometimes click very fast, the user could still select two emoji.
By the way, I only tested it as the comments guides.

@akinwale
Copy link
Contributor

@robertKozik the solution chosen looks very good, while I had tested it just now, it seems the bug still occurs, I understand that the video I uploaded is a little hard to check whether it works or not, as when the user clicks slower, the bug will not occur. After use the hook "useSingleExecution", sometimes it is ok, while sometimes click very fast, the user could still select two emoji. By the way, I only tested it as the comments guides.

Yeah, it seems it is very possible for a user to be able to click faster than the state updates, since React state updates are not immediate. Using a ref would be a better solution in that regard.

@jeet-dhandha
Copy link
Contributor

@robertKozik @tienifr Tried useSingleExecution not working.

cc632d9c-cb74-4533-b8cc-4ee401eacc75.mp4

@FabianKoder
Copy link

FabianKoder commented Aug 16, 2023

Please stay objective and not think about the missed job or opportunity. The most important thing is to improve the Expensify app and the respective code, still. So naturally the best solution should be picked. And @tienifr is the best solution concept, just that it initially didn’t work. If it wouldn’t have been easily fixable, someone else would’ve been picked. But since it was easily fixable and is a re-usable hook that can be used in many different parts of the app, this is also in my opinion the way to go. The problem probably exists in more components, so having a consistent way to fix the issue is great.

I do not think so, when the issue was not really solved, it is hard to tell whether the issue could be easily fixed or not. Find a workable way to solve the issue in actual is not that easy as we thought before the issue was solved. After the issue was solved, then we find it is such easy then ignore the man who has solved the issue initially is not fair for that man!

I understand what you are talking about, but states and refs are two very basic things in React and it is common knowledge for everyone who calls themselves React developer. Obviously @tienifr could have looked in the first proposal, or I even wrote

the useSingleExecution hook won’t work for this case as it uses an internal state which is needed as the return value can be used to change properties (or styles) of other components. If it would use a ref, no re-render would be triggered which is wanted in that case

The original proposal had another purpose, and the purpose was adapted with a common concept (state + ref combined) after it was pointed out that the original variant wouldn’t exactly work here.
Everyone, including me, could have proposed such a re-usable hook solution, but nobody except @tienifr did. So, nothing was copied. Nobody said how to fix the hook.

@jeet-dhandha
Copy link
Contributor

Also this is more of a major code change instead of fixing the underlying issue.

@gzqyl
Copy link

gzqyl commented Aug 16, 2023

Please stay objective and not think about the missed job or opportunity. The most important thing is to improve the Expensify app and the respective code, still. So naturally the best solution should be picked. And @tienifr is the best solution concept, just that it initially didn’t work. If it wouldn’t have been easily fixable, someone else would’ve been picked. But since it was easily fixable and is a re-usable hook that can be used in many different parts of the app, this is also in my opinion the way to go. The problem probably exists in more components, so having a consistent way to fix the issue is great.

I do not think so, when the issue was not really solved, it is hard to tell whether the issue could be easily fixed or not. Find a workable way to solve the issue in actual is not that easy as we thought before the issue was solved. After the issue was solved, then we find it is such easy then ignore the man who has solved the issue initially is not fair for that man!

I understand what you are talking about, but states and refs are two very basic things in React and it is common knowledge for everyone who calls themselves React developer. Obviously @tienifr could have looked in the first proposal, or I even wrote

the useSingleExecution hook won’t work for this case as it uses an internal state which is needed as the return value can be used to change properties (or styles) of other components. If it would use a ref, no re-render would be triggered which is wanted in that case

The original proposal had another purpose, and the purpose was adapted with a common concept (state + ref combined) after it was pointed out that the original variant wouldn’t exactly work here. Everyone, including me, could have proposed such a re-usable hook solution, but nobody except @tienifr did. So, nothing was copied. Nobody said how to fix the hook.

What I could not accept is that @tienifr ’s workable solution was posted after my workable codes posted.
Have you checked the two solution codes? Though @tienifr use a hook, the hook can only work with the useRef which I have posted it before, the logic to stop double click is the same with mine.
Other people also proposed useRef, but how to use the useRef, the right way to go is mine, and @tienifr does the same logic as mine!

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Aug 16, 2023
@tienifr
Copy link
Contributor

tienifr commented Aug 16, 2023

the PR is ready for review #24614

@jeet-dhandha
Copy link
Contributor

@robertKozik Waiting for a response...

@jeet-dhandha
Copy link
Contributor

@marcochavezf a request before continuing #24261 (comment) can you give this a quick look ?

Bump @marcochavezf.

@melvin-bot
Copy link

melvin-bot bot commented Sep 4, 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 @tienifr got assigned: 2023-08-16 01:51:04 Z
  • when the PR got merged: 2023-09-04 00:44:29 UTC
  • days elapsed: 12

On to the next one 🚀

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Sep 5, 2023
@melvin-bot melvin-bot bot changed the title [$1000] Compose Box - User able to select 2 emoji at a time [HOLD for payment 2023-09-12] [$1000] Compose Box - User able to select 2 emoji at a time Sep 5, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Sep 5, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 5, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Sep 5, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.63-2 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-09-12. 🎊

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
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

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

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 Sep 5, 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:

  • [@robertKozik] The PR that introduced the bug has been identified. Link to the PR:
  • [@robertKozik] 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:
  • [@robertKozik] 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:
  • [@robertKozik] Determine if we should create a regression test for this bug.
  • [@robertKozik] 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.
  • [@lschurr] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@jeet-dhandha
Copy link
Contributor

@robertKozik 😭 😭 Just once look at the comment #24261 (comment)

@lschurr
Copy link
Contributor

lschurr commented Sep 8, 2023

@robertKozik could you work on the checklist for this one? Do we need a regression test?

@lschurr
Copy link
Contributor

lschurr commented Sep 12, 2023

Payment summary:

  • Bug reporter: Applause (no payment needed)
  • Contributor: @tienifr $1000 (paid in Upwork)
  • C+: @robertKozik (No payment needed)

@robertKozik
Copy link
Contributor

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:

  • [@robertKozik] The PR that introduced the bug has been identified. Link to the PR: I don't think there was a certain PR which introduce this behaviour - probably it was there from the initial implementation
  • [@robertKozik] 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: N/A
  • [@robertKozik] 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: N/A
  • [@robertKozik] Determine if we should create a regression test for this bug. I think such cases are suitable for regression tests, as such behaviour can appear when we encounter some performance degradation. I'm all for creating one here
  • [@robertKozik] 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.
    1. Tap on a report
    2. Tap on emoji picker in compose box
    3. From smileys&emotion section, select quickly any 2 emoji
    4. Verify that only first emoji appears

CC. @lschurr

@lschurr
Copy link
Contributor

lschurr commented Sep 12, 2023

Great, this one is all set. Closing.

@lschurr lschurr closed this as completed Sep 12, 2023
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 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

9 participants