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 2024-09-07][$250] Chat - Messages stuck highlighted when opening context menus consecutively #45524

Closed
1 of 6 tasks
lanitochka17 opened this issue Jul 16, 2024 · 63 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

@lanitochka17
Copy link

lanitochka17 commented Jul 16, 2024

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: 9.0.7-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: N/A
Issue reported by: Applause - Internal Team

Action Performed:

  1. Log in to New Expensify
  2. Navigate to any chat with existing messages
  3. Right click on a message
  4. Right click on another message
  5. Click anywhere to close context menu

Expected Result:

The second clicked message should not be highlighted

Actual Result:

The second clicked message remains highlighted

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

Add any screenshot/video evidence

Bug6544401_1721161832467.2024-07-16_16-45-49.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~010fad7b2cd94a8560
  • Upwork Job ID: 1818656780802952530
  • Last Price Increase: 2024-08-07
Issue OwnerCurrent Issue Owner: @anmurali
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jul 16, 2024
Copy link

melvin-bot bot commented Jul 16, 2024

Triggered auto assignment to @anmurali (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@lanitochka17
Copy link
Author

@anmurali FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

@lanitochka17
Copy link
Author

We think that this bug might be related to #vip-vsp

@nyomanjyotisa
Copy link
Contributor

Proposal

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

Messages stuck highlighted when opening context menus consecutively

What is the root cause of that problem?

if (contextMenuRef.current.instanceID) {
hideContextMenu();
contextMenuRef.current.runAndResetOnPopoverHide();
}
contextMenuRef.current.showContextMenu(

if there is an already open context menu, we don't wait until the hideContextMenu done before executing showContextMenu

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

make showContextMenu and hideContextMenu functions async and add await to the hideContextMenu() call here

RESULT

New-Expensify.19.mp4

What alternative solutions did you explore? (Optional)

@melvin-bot melvin-bot bot added the Overdue label Jul 19, 2024
Copy link

melvin-bot bot commented Jul 22, 2024

@anmurali Eep! 4 days overdue now. Issues have feelings too...

@bernhardoj
Copy link
Contributor

bernhardoj commented Jul 24, 2024

Proposal

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

Message background is stuck when open context menu while other context menu is showing.

What is the root cause of that problem?

When we open a context menu, we pass a show and hide callback to the popover.

() => setIsContextMenuActive(true),
toggleContextMenuFromActiveReportAction,

Show callback will set the context menu active to true, while the hide callback will toggle the context menu and set it based on the context menu visibility.

When we open the first context menu and then open the second one, the hide callback of the first and second context menus is called. The hide callback is cleared when called.

Why the hide callback is called twice?

When we open a context menu, if an existing context menu is found, it will hide it first.

// If there is an already open context menu, close it first before opening
// a new one.
if (contextMenuRef.current.instanceID) {
hideContextMenu();
contextMenuRef.current.runAndResetOnPopoverHide();
}
contextMenuRef.current.showContextMenu(

hideContextMenu() will set the context menu visibility to false while runAndResetOnPopoverHide() triggers the hide callback (1st hide callback).

Because we set the visibility to false, the context menu popover onModalHide is triggered, calling another runAndResetOnPopoverHide().

  1. Open the first context menu, hide callback is set to the first context menu hide callback (callback = 1st)
  2. Open the 2nd context menu.
  • The first context menu hide callback is called (callback = empty) (hideContextMenu and runAndResetOnPopoverHide are called)
  • The second context menu hide callback is set (callback = 2nd)
  • The second context menu hide callback is called (callback = empty) (runAndResetOnPopoverHide is called by onModalHide)
  1. Close the 2nd context menu, no hide callback is called, the highlight stays

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

If we look at the popover without overlay initial implementation, they face this problem before and that's why they added the code to close the current context menu before opening a new one in this commit.

// If there is an already open context menu, close it first before opening
// a new one.
if (contextMenuRef.current.instanceID) {
hideContextMenu();
contextMenuRef.current.runAndResetOnPopoverHide();
}
contextMenuRef.current.showContextMenu(

But if you notice in the commit, we only call runAndResetOnPopoverHide to trigger the hide callback, which means we never set the context menu visibility to false (which also means the context menu never closes, just repositioned to a new position of the 2nd context menu).

But in this resolve conflict commit, they added hideContextMenu. I believe it's because to allow opening the 2nd context menu on the same message without any problem.

Why does the double hide callback happen now? I'm pretty sure it's because the component has gone through several changes. For example, if you move the setting visibility to true here

to outside the promise, then the double hide callback won't happen since setIsPopoverVisible(false) and setIsPopoverVisible(true) are called almost right after the other, so the visibility state stays true. But in the current situation, the component has enough time to re-render the component with visibility of false, which triggers the extra runAndResetOnPopoverHide.

There solution is to wait until the current context menu is completely hidden before opening a new one. hideContextMenu second param supports a hide callback which we can use to show the second context menu after the 1st one is hidden.

if (contextMenuRef.current.instanceID) {
    hideContextMenu(undefined, // show context menu);
    // no need runAndResetOnPopoverHide
    return;
}
// show context menu immediately

Also, there is another bug where the popover instance ID is never cleared, so contextMenuRef.current.instanceID is always true. To fix that, we need to clear it in runAndResetOnPopoverHide.

const runAndResetOnPopoverHide = () => {
reportIDRef.current = '-1';
reportActionIDRef.current = '-1';
originalReportIDRef.current = '-1';

setInstanceID('');

Copy link

melvin-bot bot commented Jul 24, 2024

@anmurali Still overdue 6 days?! Let's take care of this!

Copy link

melvin-bot bot commented Jul 26, 2024

@anmurali 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it!

Copy link

melvin-bot bot commented Jul 30, 2024

@anmurali this issue was created 2 weeks ago. Are we close to a solution? Let's make sure we're treating this as a top priority. Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

Copy link

melvin-bot bot commented Jul 30, 2024

@anmurali 12 days overdue. Walking. Toward. The. Light...

@muttmuure muttmuure added the External Added to denote the issue can be worked on by a contributor label Jul 31, 2024
@melvin-bot melvin-bot bot changed the title Chat - Messages stuck highlighted when opening context menus consecutively [$250] Chat - Messages stuck highlighted when opening context menus consecutively Jul 31, 2024
Copy link

melvin-bot bot commented Jul 31, 2024

Job added to Upwork: https://www.upwork.com/jobs/~010fad7b2cd94a8560

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jul 31, 2024
Copy link

melvin-bot bot commented Jul 31, 2024

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

@melvin-bot melvin-bot bot removed the Overdue label Jul 31, 2024
@hungvu193
Copy link
Contributor

Will be on my review list this tomorrow

@hungvu193
Copy link
Contributor

@nyomanjyotisa I don't think we allow using async/await at the moment. Please checkout the contributing guide here

@hungvu193
Copy link
Contributor

@bernhardoj Can you provide a little bit more about the code snippet that you mentioned here? TIA

There solution is to wait until the current context menu is completely hidden before opening a new one. hideContextMenu second param supports a hide callback which we can use to show the second context menu after the 1st one is hidden.

if (contextMenuRef.current.instanceID) {
    hideContextMenu(undefined, // show context menu);
    // no need runAndResetOnPopoverHide
    return;
}
// show context menu immediately

@bernhardoj
Copy link
Contributor

"// show context menu" is the showContextMenu code.

contextMenuRef.current.showContextMenu(
type,
event,
selection,
contextMenuAnchor,
reportID,
reportActionID,
originalReportID,
draftMessage,
onShow,
onHide,
isArchivedRoom,
isChronosReport,
isPinnedChat,
isUnreadChat,
disabledActions,
shouldCloseOnTarget,
setIsEmojiPickerActive,
isOverflowMenu,
);

So, it will look like this

if (contextMenuRef.current.instanceID) {
    hideContextMenu(undefined, () => contextMenuRef.current.showContextMenu(...));
    return;
}
contextMenuRef.current.showContextMenu(...);

@hungvu193
Copy link
Contributor

I see. I don't think it works, I still can reproduce this issue.

Screen.Recording.2024-08-02.at.09.59.14.mov

@tsa321
Copy link
Contributor

tsa321 commented Aug 2, 2024

Edited by proposal-police: This proposal was edited at 2024-08-03 02:42:43 UTC.

Proposal

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

Chat messages stuck highlighted when opening context menus consecutively

What is the root cause of that problem?

if (isVisible) {
onModalShow();
onOpen?.({
ref: withoutOverlayRef,
close: onClose,
anchorRef,
});
removeOnClose = Modal.setCloseModal(onClose);
} else {
onModalHide();
close(anchorRef);
Modal.onModalDidClose();
}

There is race codition when calling onModalHide for previous popoverWithouOverlay. So when on second right click, the popoverWithoutOverlay will call onModalHide using onModalHide fucntion of newer popoverWithoutOverlay instead of previous popoverWithoutOverly.

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

Actually we can store the instanceID in PopoverProvider. We can pass the instanceID to PopoverProvider in onOpen here:

onOpen?.({
ref: withoutOverlayRef,
close: onClose,
anchorRef,

add parameter instanceID. Then in onOpen of the PopoverProvider we add:

instanceIDRef.current = popoverParams.instanceID;

then add getContextInstanceID function in PopoverProvider:

const getContextInstaceID = () => {
     return instanceIDRef.current;
};

then in isVisible false of PopoverWithoutOverly we call onModalHide(getContextInstaceID());
Also need to adjust the OnPopoverHide ref to be an object with instanceID as key and onHide as value. then adjust the code accordingly.

The complete code is in testbranch.
Or maybe we can store onHide funciton there (need to test).

Copy link
Contributor

github-actions bot commented Aug 2, 2024

true

@tsa321
Copy link
Contributor

tsa321 commented Aug 2, 2024

@hungvu193 Here is the test branch / code changes.

Result:

macos-web-d.mp4

@bernhardoj
Copy link
Contributor

@hungvu193 I found that the instanceID is never cleared when hiding the popover, so contextMenuRef.current.instanceID is always true even though there is no active popover. So, when we try to open the popover again, it tries to hide it, but nothing to hide, so the hide callback is never called.

if (contextMenuRef.current.instanceID) {
hideContextMenu();

I have updated my proposal to fix that too.

Copy link

melvin-bot bot commented Aug 29, 2024

⚠️ Looks like this issue was linked to a Deploy Blocker here

If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

If a regression has occurred and you are the assigned CM follow the instructions here.

If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

@tsa321
Copy link
Contributor

tsa321 commented Aug 29, 2024

ignore this, my bad. Should have set the USE_REACT_STRICT_MODE to false before testing.

@hungvu193
Copy link
Contributor

@anmurali The second attempt was deployed to prod 8 days ago. This issue is now ready for payment

@anmurali
Copy link

I think this issue behooves a regression test?

@hungvu193
Copy link
Contributor

Regression Test:

  1. Open any chat that has multiple messages (or send multiple messages on the chat)
  2. Right-click on one message.
  3. Right-click on another message While the first context menu is open.
  4. Repeat it multiple times
  5. Verify the highlight of the message disappears once the context menu of the message is hidden
  6. Close the context menu
  7. Right-click on a message
  8. Verify the context menu is shown and the message is highlighted

Do we 👍 or 👎 ?

@hungvu193
Copy link
Contributor

@anmurali Can you please handle the payment summary here? Ty 😄

@roryabraham
Copy link
Contributor

This was deployed to prod on 2024-08-30 so is definitely ready for payment. Marking it as such

@roryabraham roryabraham added Awaiting Payment Auto-added when associated PR is deployed to production and removed Reviewing Has a PR in review labels Oct 4, 2024
@roryabraham roryabraham changed the title [$250] Chat - Messages stuck highlighted when opening context menus consecutively [PAY][$250] Chat - Messages stuck highlighted when opening context menus consecutively Oct 4, 2024
@melvin-bot melvin-bot bot added the Overdue label Oct 9, 2024
@luacmartins luacmartins changed the title [PAY][$250] Chat - Messages stuck highlighted when opening context menus consecutively [HOLD for payment 2024-09-07][$250] Chat - Messages stuck highlighted when opening context menus consecutively Oct 10, 2024
@luacmartins luacmartins added Daily KSv2 and removed Weekly KSv2 labels Oct 10, 2024
@melvin-bot melvin-bot bot added Daily KSv2 Overdue and removed Overdue Daily KSv2 labels Oct 10, 2024
Copy link

melvin-bot bot commented Oct 14, 2024

@anmurali, @hungvu193, @roryabraham, @bernhardoj Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

1 similar comment
Copy link

melvin-bot bot commented Oct 15, 2024

@anmurali, @hungvu193, @roryabraham, @bernhardoj Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@anmurali
Copy link

@hungvu193 is paid
Sent @bernhardoj an offer here

@melvin-bot melvin-bot bot removed the Overdue label Oct 16, 2024
@bernhardoj
Copy link
Contributor

@anmurali I've requested in ND.

@melvin-bot melvin-bot bot added the Overdue label Oct 18, 2024
@JmillsExpensify
Copy link

Can I get a payment summary with the amount for @bernhardoj?

Copy link

melvin-bot bot commented Oct 21, 2024

@anmurali, @hungvu193, @roryabraham, @bernhardoj Huh... This is 4 days overdue. Who can take care of this?

@anmurali
Copy link

anmurali commented Oct 22, 2024

Payment summary

@melvin-bot melvin-bot bot removed the Overdue label Oct 22, 2024
@JmillsExpensify
Copy link

$250 approved for @bernhardoj

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

10 participants