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

[$1000] The mini context menu hides when the last comment of a new chat is copied on Safari #18664

Closed
1 of 6 tasks
kavimuru opened this issue May 9, 2023 · 49 comments
Closed
1 of 6 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Internal Requires API changes or must be handled by Expensify staff

Comments

@kavimuru
Copy link

kavimuru commented May 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!


Action Performed:

  1. Open the app in Safari browser
  2. Click on the search icon
  3. Enter any email with which you don't have any chat history
  4. Click on the email to start the chat
  5. Send any comments
  6. Hover over the last comment
  7. Click on Copy to clipboard icon

Expected Result:

The mini context menu doesn't hide

Actual Result:

The mini context menu hides

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

Screen.Recording.2023-05-05.at.7.32.45.PM.mov
Recording.186.mp4

Expensify/Expensify Issue URL:
Issue reported by: @adeel0202
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1683297242361699

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0142123b8c491008a1
  • Upwork Job ID: 1656309577984794624
  • Last Price Increase: 2023-05-17
@kavimuru kavimuru added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels May 9, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 9, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented May 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

@kushu7
Copy link
Contributor

kushu7 commented May 9, 2023

Proposal

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

TextArea getting focused when we click copy to clipboard.

What is the root cause of that problem?

We are getting Composer as ancorNode here when we use window.getSelection() while copying last message.
isComposer is set to true.

const selection = window.getSelection();
const firstAnchorChild = selection.anchorNode && selection.anchorNode.firstChild;
const isComposer = firstAnchorChild instanceof HTMLTextAreaElement;

and here we try to set back selection to Composer. so that field gets focused resulting closing of ContextMenuActions

if (isComposer) {
firstAnchorChild.setSelectionRange(originalSelection.start, originalSelection.end, originalSelection.direction);
} else {
selection.setBaseAndExtent(originalSelection.anchorNode, originalSelection.anchorOffset, originalSelection.focusNode, originalSelection.focusOffset);
}

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

To fix this we can avoid setSelectionRange on safari desktop browser.

if (Browser.isMobileSafari()) { firstAnchorChild.setSelectionRange(originalSelection.start, originalSelection.end, originalSelection.direction); }

Screen.Recording.2023-05-10.at.1.27.14.AM.mov

What alternative solutions did you explore? (Optional)

NA

@NicMendonca
Copy link
Contributor

@NicMendonca
Copy link
Contributor

@NicMendonca
Copy link
Contributor

I understand this now. Agree we should fix to keep it consistent across platforms

@NicMendonca NicMendonca added the External Added to denote the issue can be worked on by a contributor label May 10, 2023
@melvin-bot melvin-bot bot changed the title The mini context menu hides when the last comment of a new chat is copied on Safari [$1000] The mini context menu hides when the last comment of a new chat is copied on Safari May 10, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 10, 2023

Job added to Upwork: https://www.upwork.com/jobs/~0142123b8c491008a1

@melvin-bot
Copy link

melvin-bot bot commented May 10, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented May 10, 2023

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

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

melvin-bot bot commented May 10, 2023

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

@kushu7
Copy link
Contributor

kushu7 commented May 10, 2023

My proposal above

@dukenv0307
Copy link
Contributor

dukenv0307 commented May 11, 2023

Proposal

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

The mini context menu hides when the last comment of a new chat is copied on Safari

What is the root cause of that problem?

const selection = window.getSelection();
const firstAnchorChild = selection.anchorNode && selection.anchorNode.firstChild;
const isComposer = firstAnchorChild instanceof HTMLTextAreaElement;
let originalSelection = null;

We are checking if firstAnchorChild is HTMLTextAreaElement we will focus on it
if (isComposer) {
firstAnchorChild.setSelectionRange(originalSelection.start, originalSelection.end, originalSelection.direction);
} else {
selection.setBaseAndExtent(originalSelection.anchorNode, originalSelection.anchorOffset, originalSelection.focusNode, originalSelection.focusOffset);
}

As mentioned here

Window.getSelection() will either give the selected range or the cursor position. As we are running the syn operation on Safari, it is called before the composer is actually blurred thus the selection contains the cursor position.

It is the reason why when clicking Copy to Clipboard Icon on the last comment, selection.anchorNode will be the main composer and isComposer is true

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

function setHTMLSync(html, text) {

const setHtml = (html, text) => {

In both setHtml and setHTMLSync functions, we can define new param is called blurActiveinput. At the beginning of SetHTMLSync, we will call document.activeElement.blur() if blurActiveinput is true.
And pass blurActiveinput is true in

Clipboard.setHtml(content, plainText);

What alternative solutions did you explore? (Optional)

const isComposer = firstAnchorChild instanceof HTMLTextAreaElement;

Here, we should add one more condition to check if the user selects text by clicking Copy to Clipboard Icon. If true, isComposer will be false
const isComposer = firstAnchorChild instanceof HTMLTextAreaElement && selection.type === 'Range';
Because when clicking Copy to Clipboard Icon, selection.type === 'Caret';

Result

Just checked again and It works well

Screen-Recording-2023-05-11-at-17.11.37.mp4

@melvin-bot melvin-bot bot added the Overdue label May 12, 2023
@robertjchen
Copy link
Contributor

Thanks for all the proposals so far, we will evaluate this week.

@melvin-bot melvin-bot bot removed the Overdue label May 15, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 17, 2023

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

@melvin-bot melvin-bot bot added the Overdue label May 17, 2023
@NicMendonca
Copy link
Contributor

@robertjchen any update here?

@melvin-bot melvin-bot bot removed the Overdue label May 17, 2023
@parasharrajat
Copy link
Member

My bad, Catching up here. Give me sometime to review these.

@parasharrajat
Copy link
Member

parasharrajat commented May 19, 2023

Thanks for the proposals. Both of proposals' root cause is incomplete. We should try to explain Why as well.

  1. Anchor Node is incorrect but Why?

So this happens on Safari. On Safari we are using SetHTMLSync which is a synchronous method. Window.getSelection() will either give the selected range or the cursor position. As we are running the syn operation on Safari, it is called before the composer is actually blurred thus the selection contains the cursor position.
On another browser, we are using async Clipboard API which is called after the composer is blurred so the selection object no more has a cursor position.

This was the reason I renamed this function to setHtmlSync so that these bugs are easier to catch. #13396 (comment)


About the solutions.
@kushu7 's proposal breaks the existing functionality.
@dukenv0307 I am still thinking about your solution. Does it fit well with the original implementation #14506?

IMO, we can blur the composer before the sync clipboard set, it should resolve the issue. document.activeElement.blur() can do that.

So an alternative will be:

  1. from CopyToClipboardAction pass down the argument saying blurActiveinput and then call ``document.activeElement.blur()in the SetHTMLSync when this argument istrue`.

@dukenv0307
Copy link
Contributor

@parasharrajat Thanks for your explanation. I just updated proposal as your suggestion and test again. It works well
One small question, could we always call document.activeElement.blur() at the beginning of SetHTMLSync function and don't need more params

@tjferriss
Copy link
Contributor

Yes, agreed. @parasharrajat @adeel0202 I have sent you both an offer in Upworks for the job.

@dukenv0307 I couldn't find you in Upworks. Can you please apply here: https://www.upwork.com/jobs/~0142123b8c491008a1

@tjferriss tjferriss reopened this May 31, 2023
@melvin-bot melvin-bot bot added the Overdue label May 31, 2023
@dukenv0307
Copy link
Contributor

@tjferriss applied, thank you!

@melvin-bot melvin-bot bot removed the Overdue label May 31, 2023
@tjferriss
Copy link
Contributor

Reporting bonus paid to @adeel0202

Waiting on @parasharrajat and @dukenv0307 to accept offers to be paid. Then we can close the issue.

@melvin-bot melvin-bot bot added the Overdue label Jun 2, 2023
@parasharrajat
Copy link
Member

@tjferriss Done.

@melvin-bot melvin-bot bot removed the Overdue label Jun 2, 2023
@robertjchen
Copy link
Contributor

waiting on @dukenv0307

@dukenv0307
Copy link
Contributor

@robertjchen I've accepted, thanks!

@melvin-bot
Copy link

melvin-bot bot commented Jun 6, 2023

@robertjchen @parasharrajat @NicMendonca @dukenv0307 this issue is now 4 weeks old and preventing us from maintaining WAQ, can you:

  • Decide whether any proposals currently meet our guidelines and can be approved as-is today
  • If no proposals meet that standard, please take this issue internal and treat it as one of your highest priorities
  • If you have any questions, don't hesitate to start a discussion in #expensify-open-source

Thanks!

@melvin-bot melvin-bot bot added Internal Requires API changes or must be handled by Expensify staff and removed External Added to denote the issue can be worked on by a contributor labels Jun 6, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jun 6, 2023

Current assignee @parasharrajat is eligible for the Internal assigner, not assigning anyone new.

@parasharrajat
Copy link
Member

parasharrajat commented Jun 7, 2023

@NicMendonca Can we please take the necessary actions on this and close it?

@robertjchen
Copy link
Contributor

Thanks all, I think this can be closed.

@parasharrajat
Copy link
Member

@robertjchen Payments are pending on this for me.

@parasharrajat
Copy link
Member

Bump @tjferriss

@NicMendonca
Copy link
Contributor

I've paid everyone out! 🎉 thank you!

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 Internal Requires API changes or must be handled by Expensify staff
Projects
None yet
Development

No branches or pull requests

7 participants