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-10-09] [$500] Web - Pasting emojis freezes cursor position in composer box (works fine in edit message) #27672

Closed
2 of 6 tasks
kbecciv opened this issue Sep 18, 2023 · 25 comments
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

@kbecciv
Copy link

kbecciv commented Sep 18, 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. React to any message with any emoji
  4. Right click on reaction and copy the emoji text
  5. Paste the copied emoji text few times in compose box and observe that cursor is freezes after first pasted emoji
  6. Try to paste similarly in edit message and observe that it works fine

Expected Result:

App should move cursor to end on pasting the emojis in compose box as it does in edit message box

Actual Result:

App freezes cursor after first pasted emoji in compose box

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.71.4
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

pasting.emoji.in.composer.freezes.the.cursor.position.mp4
Recording.4556.mp4

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

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0141004fff370e0c4e
  • Upwork Job ID: 1703759230392123392
  • Last Price Increase: 2023-09-25
  • Automatic offers:
    • Ollyws | Reviewer | 26897303
    • jeet-dhandha | Contributor | 26897305
    • dhanashree-sawant | Reporter | 26897308
@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 18, 2023
@ahmedGaber93
Copy link
Contributor

ahmedGaber93 commented Sep 18, 2023

Proposal

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

Pasting emojis freezes cursor position in composer box (works fine in edit message)

What is the root cause of that problem?

wrong calculation by getCommonSuffixLength here

const remainder = ComposerUtils.getCommonSuffixLength(commentRef.current, newComment);

function getCommonSuffixLength(str1, str2) {
let i = 0;
while (str1[str1.length - 1 - i] === str2[str2.length - 1 - i]) {
i++;
}
return i;
}

how getCommonSuffixLength work? see this example

const reminder = getCommonSuffixLength("START :joy END", "START 😂 END"); // CommonSuffix is ` END` and length 4.  
const newSelection  = "START 😂 END".length - reminder; // result 12 - 4 = 8
// cursor position 8 is true and set after the emoji

Why it failed in this case.
because when matching the CommonSuffix the replaced emoji joy 😂 is match the previous of it, so it not stop on it

// note "😂 ".length is 3
const reminder = getCommonSuffixLength("😂 ", "😂 😂 "); // resul 3
const newSelection  = "😂 😂 ".length - reminder; // result 6 - 3 = 3
const reminder = getCommonSuffixLength("😂 😂 ", "😂 😂 😂 "); // resul 6
const newSelection  = "😂 😂 😂 ".length - reminder; // result 9 - 6 = 3
const reminder = getCommonSuffixLength("😂 😂 😂 ", "😂 😂 😂 😂 "); // resul 9
const newSelection  = "😂 😂 😂 😂 ".length - reminder; // result 12 - 9 = 3

whatever we type the newSelection is 3.

// CommonSuffix between `😂 😂 cursor here 😂` and  `😂 😂 😂 😂 ` should be only `😂 `
// but becaue the replace emoji match the previous of it, CommonSuffix wii be 😂 😂 😂

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

Reverse the way we used to get the new position.
Old way comment.length - CommonSuffix.length "START 😂 END" - " END"
new way CommonPrefix + emoji.length + space.length "START" + 😂 + " "

What is the different in the new way?

when we use CommonPrefix we will stop in the current cursor position, so if the replaced emoji match the next of it, it not affect because we will stop in the current cursor position

// add this new method on ComposerUtils
function getCommonPrefixLength(str1, str2, end) {
    let i = 0;
    while (str1[i] === str2[i] && i < end) { // start from i not length - 1 - i and i < end will do the disired fix.
        i++;
    }
    return i;
}

and the emoji length and newSelectionPosition length

if (commentValue !== newComment) {
    const remainder = ComposerUtils.getCommonPrefixLength(commentRef.current, newComment, selection.end);
    const emojiLength = newComment.substring(remainder).match(CONST.REGEX.EMOJIS)[0].length;
    const spaceAfterEmojiLength = 1;
    const newSelectionPosition = remainder + emojiLength + spaceAfterEmojiLength;
    setSelection({
        start: newSelectionPosition,
        end: newSelectionPosition,
    });
}

we need to add selection.end in callback deps

result

Screen.Recording.2023-09-18.at.1.34.22.AM.mov

What alternative solutions did you explore? (Optional)

N/A

@melvin-bot melvin-bot bot changed the title Web - Pasting emojis freezes cursor position in composer box (works fine in edit message) [$500] Web - Pasting emojis freezes cursor position in composer box (works fine in edit message) Sep 18, 2023
@melvin-bot
Copy link

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

Job added to Upwork: https://www.upwork.com/jobs/~0141004fff370e0c4e

@melvin-bot
Copy link

melvin-bot bot commented Sep 18, 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 melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Sep 18, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 18, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Sep 18, 2023

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

@jeet-dhandha
Copy link
Contributor

jeet-dhandha commented Sep 18, 2023

Proposal

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

  • Cursor staying after the first emoji in the text input when continuosly pasting ":joy:".

What is the root cause of that problem?

  • Cursor position is not being as we are comparing wrong values. commentRef.current & newComment

const remainder = ComposerUtils.getCommonSuffixLength(commentRef.current, newComment);

  • I am still not sure why we are comparing commentRef.current with newComment instead of commentValue.

  • As in below example newComment will always be different then commentValue as :joy: text will parsed to emoji.

const commentValue = ":joy:";
const newComment = " 😂 "; // After parsing

const isEqual = commentValue === newComment; // false

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

  • We should compare the newComment with the commentValue instead of commentRef.current.

What alternative solutions did you explore? (Optional)

  • N/A

@Christinadobrzyn
Copy link
Contributor

This is reproducible and I can't find another GH related so I think we can move forward with reviewing these proposals.

@lschurr lschurr removed their assignment Sep 19, 2023
@Christinadobrzyn
Copy link
Contributor

Hi @Ollyws would you be able to take a peek at the proposals to see if they will work?

@melvin-bot melvin-bot bot added the Overdue label Sep 22, 2023
@Ollyws
Copy link
Contributor

Ollyws commented Sep 22, 2023

Will review asap.

@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@Ollyws
Copy link
Contributor

Ollyws commented Sep 25, 2023

Couldn't get to this one today will review it tomorrow.

@melvin-bot melvin-bot bot removed the Overdue label Sep 25, 2023
@Ollyws
Copy link
Contributor

Ollyws commented Sep 26, 2023

It seems when getCommonSuffixLength was originally implemented in #22827 it was being passed the value that is passed to replaceEmojis (newComment) along with the resulting value.

When ReportActionCompose was migrated to a functional component this was for some reason changed to use commentRef.current which as @jeet-dhandha pointed out, is incorrect.

So I like @jeet-dhandha's proposal as we're simply changing the commentRef.current back to it's originally intended value.

🎀👀🎀 C+ reviewed

@melvin-bot
Copy link

melvin-bot bot commented Sep 26, 2023

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

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

melvin-bot bot commented Sep 27, 2023

📣 @Ollyws 🎉 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 Sep 27, 2023

📣 @jeet-dhandha 🎉 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 Sep 27, 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

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Sep 27, 2023
@jeet-dhandha
Copy link
Contributor

@Ollyws - PR Ready for Review.

@melvin-bot
Copy link

melvin-bot bot commented Sep 28, 2023

🎯 ⚡️ Woah @Ollyws / @jeet-dhandha, great job pushing this forwards! ⚡️

The pull request got merged within 3 working days of assignment, so this job is eligible for a 50% #urgency bonus 🎉

  • when @jeet-dhandha got assigned: 2023-09-27 02:58:33 Z
  • when the PR got merged: 2023-09-28 03:06:40 UTC

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 Oct 2, 2023
@melvin-bot melvin-bot bot changed the title [$500] Web - Pasting emojis freezes cursor position in composer box (works fine in edit message) [HOLD for payment 2023-10-09] [$500] Web - Pasting emojis freezes cursor position in composer box (works fine in edit message) Oct 2, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Oct 2, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 2, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Oct 2, 2023

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

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

  • [@Ollyws] The PR that introduced the bug has been identified. Link to the PR:
  • [@Ollyws] 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:
  • [@Ollyws] 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:
  • [@Ollyws] Determine if we should create a regression test for this bug.
  • [@Ollyws] 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.
  • [@Christinadobrzyn] 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 Daily KSv2 labels Oct 9, 2023
@Ollyws
Copy link
Contributor

Ollyws commented Oct 10, 2023

BugZero Checklist:

The PR that introduced the bug has been identified. Link to the PR: #18648

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/18648/files#r1352333250

I don't think a regression test would be helpful here as it's not related to an important user flow nor is it very impactful.

@jeet-dhandha
Copy link
Contributor

Bump for Payment.

@Christinadobrzyn
Copy link
Contributor

Payouts due:

Issue Reporter: $50 @dhanashree-sawant (paid in Upwork)
Contributor: $500 + $250 bonus @jeet-dhandha (paid in Upwork)
Contributor+: $500 + $250 bonus @Ollyws (paid in Upwork)

Eligible for 50% #urgency bonus? Y - based on #27672 (comment)

Upwork job is here (it's now closed so let me know if you need something)

Closing as complete!

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

7 participants