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

[Awaiting Checklist] [$500] Cursor freeze on paste emoji in edit message #29128

Closed
4 of 6 tasks
m-natarajan opened this issue Oct 9, 2023 · 24 comments
Closed
4 of 6 tasks
Assignees
Labels
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

@m-natarajan
Copy link

m-natarajan commented Oct 9, 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!


Version Number: 1.3.79-3
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
Expensify/Expensify Issue URL:
Issue reported by: @dhanashree-sawant
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1696835638613239

Action Performed:

  1. Open the app
  2. Open any report
  3. Send any message
  4. React to any other message with any emoji and right click on reaction
  5. Copy emoji text
  6. Edit message sent in step 3
  7. Paste the emoji text few times and observe that cursor position freezes

Expected Result:

App should not freeze cursor position on paste of emoji

Actual Result:

App freezes cursor position on paste of emoji in edit message

Workaround:

Unknown

Platforms:

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

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Android: Native
Android: mWeb Chrome
android.chrome.paste.edit.message.freeze.cursor.mp4
iOS: Native
iOS: mWeb Safari
ios.native.safari.paste.edit.mesage.freeze.cursor.mov
MacOS: Chrome / Safari
mac.chrome.paste.edit.mesage.freeze.cursor.mov
emoji.mp4
MacOS: Desktop
mac.desktop.paste.edit.mesage.freeze.cursor.mov

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0157837cc3b2f27ed2
  • Upwork Job ID: 1711488681499811840
  • Last Price Increase: 2023-10-09
  • Automatic offers:
    • jjcoffee | Reviewer | 27159501
    • Krishna2323 | Contributor | 27159503
    • dhanashree-sawant | Reporter | 27159505
Issue OwnerCurrent Issue Owner: @jjcoffee
@m-natarajan m-natarajan added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Oct 9, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 9, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Oct 9, 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

@m-natarajan m-natarajan added the External Added to denote the issue can be worked on by a contributor label Oct 9, 2023
@melvin-bot melvin-bot bot changed the title Cursor freeze on paste emoji in edit message [$500] Cursor freeze on paste emoji in edit message Oct 9, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 9, 2023

Job added to Upwork: https://www.upwork.com/jobs/~0157837cc3b2f27ed2

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

melvin-bot bot commented Oct 9, 2023

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

@m-natarajan m-natarajan added Help Wanted Apply this label when an issue is open to proposals by contributors and removed Daily KSv2 Help Wanted Apply this label when an issue is open to proposals by contributors Bug Something is broken. Auto assigns a BugZero manager. labels Oct 9, 2023
@Krishna2323
Copy link
Contributor

Krishna2323 commented Oct 9, 2023

Proposal

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

Cursor freeze on paste emoji in edit message

What is the root cause of that problem?

In the current approach, we utilized the functional form of setState, a method that accepts a function returning the new state. Within this function, the cursor's position was calculated based on prevDraft (the prior state). The crux of the problem is that this functional form of setState doesn't always have immediate access to the most recent state. The asynchronous nature of React's state updates means that prevDraft could potentially reflect an outdated draft version by the time the cursor's position was calculated. This misalignment, wherein the cursor position was determined using potentially outdated information, was causing the observed erratic cursor movement.

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

By directly setting the draft state with setDraft(newDraft) and then calculating the cursor position outside of this state update, we ensure that the cursor's placement is based strictly on the most recent user input and the resulting draft transformation.

Current Implementation:

setDraft((prevDraft) => {
if (newDraftInput !== newDraft) {
const remainder = ComposerUtils.getCommonSuffixLength(prevDraft, newDraft);
setSelection({
start: newDraft.length - remainder,
end: newDraft.length - remainder,
});
}
return newDraft;
});

Updated:

// First, directly update the draft with the new value.
setDraft(newDraft);

if (newDraftInput !== newDraft) {
    const remainder = ComposerUtils.getCommonSuffixLength(newDraftInput, newDraft);
    
        setSelection({
        start: newDraft.length - remainder,
        end: newDraft.length - remainder,
    });
}

We also use the same approach in ComposerWithSuggestions when calling updateComment.

const updateComment = useCallback(
(commentValue, shouldDebounceSaveComment) => {
raiseIsScrollLikelyLayoutTriggered();
const {text: newComment, emojis} = EmojiUtils.replaceAndExtractEmojis(commentValue, preferredSkinTone, preferredLocale);
if (!_.isEmpty(emojis)) {
insertedEmojisRef.current = [...insertedEmojisRef.current, ...emojis];
debouncedUpdateFrequentlyUsedEmojis();
}
setIsCommentEmpty(!!newComment.match(/^(\s)*$/));
setValue(newComment);
if (commentValue !== newComment) {
// Ensure emoji suggestions are hidden even when the selection is not changed (so calculateEmojiSuggestion would not be called).
if (suggestionsRef.current) {
suggestionsRef.current.resetSuggestions();
}
const remainder = ComposerUtils.getCommonSuffixLength(commentValue, newComment);
setSelection({
start: newComment.length - remainder,
end: newComment.length - remainder,
});
}
// Indicate that draft has been created.
if (commentRef.current.length === 0 && newComment.length !== 0) {
Report.setReportWithDraft(reportID, true);
}
// The draft has been deleted.
if (newComment.length === 0) {
Report.setReportWithDraft(reportID, false);
}
commentRef.current = newComment;
if (shouldDebounceSaveComment) {
debouncedSaveReportComment(reportID, newComment);
} else {
Report.saveReportComment(reportID, newComment || '');
}
if (newComment) {
debouncedBroadcastUserIsTyping(reportID);
}
},
[
debouncedUpdateFrequentlyUsedEmojis,
preferredLocale,
preferredSkinTone,
reportID,
setIsCommentEmpty,
suggestionsRef,
raiseIsScrollLikelyLayoutTriggered,
debouncedSaveReportComment,
],
);

Result

Screen.Recording.2023-10-10.at.3.41.31.AM.mp4

@melvin-bot melvin-bot bot added the Daily KSv2 label Oct 9, 2023
@m-natarajan m-natarajan added the Bug Something is broken. Auto assigns a BugZero manager. label Oct 10, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 10, 2023

Current assignee @twisterdotcom is eligible for the Bug assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Oct 10, 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

@jjcoffee
Copy link
Contributor

@Krishna2323 Thanks for your proposal! The text is a bit dense, so I'd appreciate a bit more of a clear & concise RCA. I also would prefer if you broke down what changes you are making and where. Could you update your proposal with these changes?

@Krishna2323
Copy link
Contributor

@jjcoffee, proposal updated.

@jjcoffee
Copy link
Contributor

Thanks! @Krishna2323's proposal LGTM.

🎀👀🎀 C+ reviewed

@melvin-bot
Copy link

melvin-bot bot commented Oct 11, 2023

Triggered auto assignment to @Beamanator, 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 Oct 12, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 12, 2023

📣 @jjcoffee 🎉 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 12, 2023

📣 @Krishna2323 🎉 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 12, 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 Oct 12, 2023
@Krishna2323
Copy link
Contributor

@jjcoffee, PR ready for review.

@melvin-bot
Copy link

melvin-bot bot commented Oct 16, 2023

🎯 ⚡️ Woah @jjcoffee / @Krishna2323, 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 @Krishna2323 got assigned: 2023-10-12 12:34:35 Z
  • when the PR got merged: 2023-10-16 11:53:41 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 17, 2023
@melvin-bot melvin-bot bot changed the title [$500] Cursor freeze on paste emoji in edit message [HOLD for payment 2023-10-24] [$500] Cursor freeze on paste emoji in edit message Oct 17, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Oct 17, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 17, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Oct 17, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.85-4 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-24. 🎊

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

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

Payment summary:
@jjcoffee paid $750 here: https://www.upwork.com/nx/wm/offer/27159501 (Reviewer)
@Krishna2323 paid $750 here: https://www.upwork.com/nx/wm/offer/27159503 (Contributor)
@dhanashree-sawant paid $50 here: https://www.upwork.com/nx/wm/offer/27159505 (Reporter)

@twisterdotcom twisterdotcom changed the title [HOLD for payment 2023-10-24] [$500] Cursor freeze on paste emoji in edit message [Awaiting Checklist] [$500] Cursor freeze on paste emoji in edit message Oct 24, 2023
@twisterdotcom twisterdotcom removed the Awaiting Payment Auto-added when associated PR is deployed to production label Oct 24, 2023
@melvin-bot melvin-bot bot added the Overdue label Oct 26, 2023
@twisterdotcom
Copy link
Contributor

Bump on the checklist @jjcoffee.

@jjcoffee
Copy link
Contributor

jjcoffee commented Oct 27, 2023

  • The PR that introduced the bug has been identified. Link to the PR: Fix cursor position when adding emoji #12632
  • 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: Fix cursor position when adding emoji #12632 (comment)
  • 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
  • Determine if we should create a regression test for this bug. Yes
  • 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.

Regression test proposal

  1. Copy any emoji text, e.g. :smile:
  2. Open any report and edit any message
  3. Paste the emoji text copied in step 1 a few times in quick succession
  4. Verify that the cursor position correctly updates to the end of each inserted emoji

Do we agree 👍 or 👎

@jjcoffee
Copy link
Contributor

@twisterdotcom Sorry, missed this one - added the checklist now!

@melvin-bot melvin-bot bot added the Overdue label Oct 30, 2023
@twisterdotcom
Copy link
Contributor

Sorted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

5 participants