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-11-01] [HOLD for payment 2023-10-13] [$500] Chat - App displays mention suggestion for sometime when we remove space from before @ #28170

Closed
6 tasks done
kbecciv opened this issue Sep 25, 2023 · 40 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@kbecciv
Copy link

kbecciv commented Sep 25, 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. Open the app
  2. Open any report
  3. Type @, it will trigger mention suggestions
  4. Add space before @
  5. Remove the space and observe that suggestions are displayed for sometime and then dismissed

Expected Result:

App should not display suggestions on removing space before @

Actual Result:

App displays suggestions on removing space before @ for sometime

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.74.0
Reproducible in staging?: y
Reproducible in production?: y
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

suggestion.before.@.on.space.remove.windows.chrome.mp4
suggestion.before.@.on.space.remove.android.mp4
suggestion.before.@.on.space.remove.mac.desktop.mac.chrome.ios.both.mov
Recording.4759.mp4
Screen_Recording_20230928_080226_New.Expensify.1.mp4

Expensify/Expensify Issue URL:
Issue reported by: @dhanashree-sawant
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1695458107547879

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0193240eea08f27c8d
  • Upwork Job ID: 1706350665337753600
  • Last Price Increase: 2023-09-25
  • Automatic offers:
    • cubuspl42 | Reviewer | 26974438
    • paultsimura | Contributor | 26974441
    • dhanashree-sawant | Reporter | 26974442
@kbecciv kbecciv added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Sep 25, 2023
@melvin-bot melvin-bot bot changed the title Chat - App displays mention suggestion for sometime when we remove space from before @ [$500] Chat - App displays mention suggestion for sometime when we remove space from before @ Sep 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

Job added to Upwork: https://www.upwork.com/jobs/~0193240eea08f27c8d

@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

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

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

melvin-bot bot commented Sep 25, 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

@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

Triggered auto assignment to @stephanieelliott (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

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

@paultsimura
Copy link
Contributor

paultsimura commented Sep 25, 2023

Proposal

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

The mentions suggestion appears for a moment when the symbol before "@" is removed.

What is the root cause of that problem?

The root cause is in this hook:

useEffect(() => {
calculateMentionSuggestion(selection.end);
}, [selection, calculateMentionSuggestion]);

It is supposed to run only when the selection changes. However, calculateMentionSuggestion is also in the dependencies list of this hook. And this function has the value in its dependencies list:

[getMentionOptions, personalDetails, resetSuggestions, setHighlightedMentionIndex, value],

This leads to the calculateMentionSuggestion function being changed every time a value is changed. And therefore the initial hook is called on every selection & value change.

The hook is called 2 times on every change:

  1. With changed value but previous selection
  2. With changed value and new selection

As a result, on step 1, the cursor is calculated as standing after the "@" sign:
image

And the menu becomes visible in this chunk of code until the step 2 takes place:

if (!isCursorBeforeTheMention && isMentionCode(lastWord)) {
const suggestions = getMentionOptions(personalDetails, prefix);
nextState.suggestedMentions = suggestions;
nextState.shouldShowSuggestionMenu = !_.isEmpty(suggestions);
}

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

We should execute this hook only if the selection has changed:

Option 1 (preferred, although not lint-friendly):

    useEffect(() => {
        calculateMentionSuggestion(selection.end);
        
+       // we want this hook to run only on selection change
+       // eslint-disable-next-line react-hooks/exhaustive-deps
+   }, [selection]);
-   }, [selection, calculateMentionSuggestion]);

What alternative solutions did you explore? (Optional)

Option 2 (lint-friendly, but with more complex checks):

    const prevSelection = usePrevious(selection);
    const didSelectionChange = !_.isEqual(prevSelection, selection);

    useEffect(() => {
        if (!didSelectionChange) {
            return;
        }

        calculateMentionSuggestion(selection.end);
    }, [didSelectionChange, selection, calculateMentionSuggestion]);

@melvin-bot melvin-bot bot added the Overdue label Sep 28, 2023
@zanyrenney
Copy link
Contributor

dupe assignment, i got this @stephanieelliott - unassigning you.

@melvin-bot melvin-bot bot removed the Overdue label Sep 29, 2023
@cubuspl42
Copy link
Contributor

I approve the proposal by @paultsimura. The RCA looks fine, and the fix is simple.

C+ reviewed 🎀 👀 🎀

@melvin-bot
Copy link

melvin-bot bot commented Sep 29, 2023

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

@lakchote
Copy link
Contributor

lakchote commented Oct 2, 2023

Solution looks good to me. Assigning now.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Oct 2, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 2, 2023

📣 @cubuspl42 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

@melvin-bot
Copy link

melvin-bot bot commented Oct 2, 2023

📣 @paultsimura 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer 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 📖

@melvin-bot
Copy link

melvin-bot bot commented Oct 2, 2023

📣 @dhanashree-sawant 🎉 An offer has been automatically sent to your Upwork account for the Reporter role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

@cubuspl42
Copy link
Contributor

@stephanieelliott I don't think we're eligible for payment here, at least for now. We had to revert the solution, and we're still investigating other options that will both solve this issue and don't have undesired side effects.

The fact that this is related to a bug in React Native itself doesn't help.

@paultsimura What's the latest status here? I know you've been discussing this on Slack

@zanyrenney
Copy link
Contributor

Yep, i think you're right @cubuspl42 this wouldn't qualify for payment. Let's link the slack conversation if there is one?

@paultsimura
Copy link
Contributor

Yep, i think you're right @cubuspl42 this wouldn't qualify for payment. Let's link the slack conversation if there is one?

Here's the conversation, unfortunately it doesn't get the responses quite frequently:
https://expensify.slack.com/archives/C01GTK53T8Q/p1696421170146759

@cubuspl42
Copy link
Contributor

@paultsimura Did we explore the "Option 2 (lint-friendly, but with more complex checks)"? Does it also has the undesired side-effects?

@paultsimura
Copy link
Contributor

@cubuspl42 unfortunately yes, it had the same side-effect.
However, I've come up with a new workaround approach that seem to do the job. Would you be able to test this approach anytime soon?

In SuggestionMention:

  1. Add a new state variable:
const [shouldRecalculateSuggestions, setShouldRecalculateSuggestions] = useState(false);
  1. Modify the hook I initially wanted to modify:
    useEffect(() => {
+        if (selection.end > 0 && !lodashGet(value, 'length', 0)) {
+            // This is a workaround for a known issue with iOS' first input.
+            // See: https://github.com/facebook/react-native/pull/36930#issuecomment-1593028467
+            setShouldRecalculateSuggestions(true);
+        }
        calculateMentionSuggestion(selection.end);

+        // We want this hook to run only on selection change.
+        // eslint-disable-next-line react-hooks/exhaustive-deps
+    }, [selection.end]);
-    }, [selection, calculateMentionSuggestion]);
  1. Add a new hook:
    useEffect(() => {
        // This hook solves the issue with iOS' first input:
        // It enables showing the mention suggestions after the user enters '@' as a first char in the Composer.
        // See: https://github.com/facebook/react-native/pull/36930#issuecomment-1593028467
        if (!shouldRecalculateSuggestions) {
            return;
        }

        setShouldRecalculateSuggestions(false);
        calculateMentionSuggestion(selection.end);

        // We want this hook to run only on value change.
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [value]);

This will allow handling the regression that was discovered, when the first input in RN iOS is handled in the wrong order:

Simulator.Screen.Recording.-.iPhone.15.-.2023-10-17.at.16.06.15.mp4

@shubham1206agra
Copy link
Contributor

Please test #28749 with the proposed solution

@zanyrenney
Copy link
Contributor

who are you asking to test @shubham1206agra - please add the specific user you are directing your comments too so that we can understand better and keep pushing this forward with urgency?

@cubuspl42
Copy link
Contributor

@paultsimura Do you have a Git branch with these changes at hand?

@paultsimura
Copy link
Contributor

@cubuspl42 here it is: https://github.com/paultsimura/Expensify/tree/fix/28170-mention-on-delete
However, @shubham1206agra is right – this brings back the #28749. Working on it...

@paultsimura
Copy link
Contributor

paultsimura commented Oct 17, 2023

Ok, seems like I have a workaround that covers all the cases I currently know. It's not elegant, but it's working:

+   const previousValue = usePrevious(value);

    useEffect(() => {
+       if (value.length < previousValue.length) {
+           return;
+       }

        calculateMentionSuggestion(selection.end);
    }, [selection, calculateMentionSuggestion]);

Since the hook is called 2 times: on value change and on selection change, it's safe to early return on deletion – in this case, only the correct update of value and selection should trigger the suggestions. On the input, the hook will still be called 2 times, so both normal (non-iOS) and buggy iOS flows should be covered.

@cubuspl42 please test when you have a spare minute. The changes are in the branch already (with some debugging logs for the moment).
cc: @shubham1206agra

@cubuspl42
Copy link
Contributor

@paultsimura This might be working! But would you also test this branch and share your thoughts?

@paultsimura
Copy link
Contributor

@paultsimura This might be working! But would you also test this branch and share your thoughts?

Unfortunately, the branch doesn't solve the current issue, does it work for you @cubuspl42 ?

Screen.Recording.2023-10-18.at.16.23.57.mov

It's almost the same dependencies set as in current production – the calculateMentionSuggestion in our hook's dependencies changes with every value change (which is in calculateMentionSuggestion's dependencies list). So replacing calculateMentionSuggestion with value eventually doesn't change anything, as far as I can see 🤔

@cubuspl42
Copy link
Contributor

But would you also test this branch and share your thoughts?

@paultsimura Forget this. This doesn't work, as you observed. I tried really many work-around ideas (none worked) and I think I forgot what problem I'm workarounding in the end, however dumb that sounds.

@paultsimura
Copy link
Contributor

I forgot what problem I'm workarounding in the end

I had the exact same situation at some point😅
It was because I was trying to find a workaround that solves all the issues at once. But after none of them worked, moved to just straightforward "don't show suggestions on removal" workaround.

@cubuspl42
Copy link
Contributor

You can file a PR with your best idea so far, we can move the discussion there

@melvin-bot
Copy link

melvin-bot bot commented Oct 23, 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 @paultsimura got assigned: 2023-10-02 07:02:43 Z
  • when the PR got merged: 2023-10-23 14:21:57 UTC
  • days elapsed: 15

On to the next one 🚀

@melvin-bot melvin-bot bot added Weekly KSv2 and removed Weekly KSv2 labels Oct 25, 2023
@melvin-bot melvin-bot bot changed the title [HOLD for payment 2023-10-13] [$500] Chat - App displays mention suggestion for sometime when we remove space from before @ [HOLD for payment 2023-11-01] [HOLD for payment 2023-10-13] [$500] Chat - App displays mention suggestion for sometime when we remove space from before @ Oct 25, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Oct 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 25, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Oct 25, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.90-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-11-01. 🎊

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 Oct 25, 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:

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

@zanyrenney
Copy link
Contributor

@cubuspl42 requires payment offer (Reviewer) - paid $500
@paultsimura requires payment offer (Contributor) paid $500
@dhanashree-sawant requires payment offer (Reporter) paid $50

no bonus as 15 days elapsed.

all payments complete. Closing!

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. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
None yet
Development

No branches or pull requests

8 participants