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

[PAID] [LOW] [$500] Web - Chat - Console error shows up when opening emoji picker and then clicking on send button #32743

Closed
1 of 6 tasks
lanitochka17 opened this issue Dec 8, 2023 · 57 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 Engineering External Added to denote the issue can be worked on by a contributor

Comments

@lanitochka17
Copy link

lanitochka17 commented Dec 8, 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.4.10-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
Expensify/Expensify Issue URL:
Issue reported by: Applause - Internal Team
Slack conversation:

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to any chat
  3. Click on the emoji picker
  4. Click Send button

Expected Result:

No console error

Actual Result:

Console error shows up - Uncaught TypeError: Cannot read properties of null (reading 'onCloseCallback')

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

Bug6306170_1702063410475.20231209_014314__1_.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~017a72f5508e45e17d
  • Upwork Job ID: 1733213660108169216
  • Last Price Increase: 2024-01-05
  • Automatic offers:
    • hoangzinh | Reviewer | 28128112
    • mkhutornyi | Contributor | 28128113
@lanitochka17 lanitochka17 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 Dec 8, 2023
@melvin-bot melvin-bot bot changed the title Web - Chat - Console error shows up when opening emoji picker and then clicking on send button [$500] Web - Chat - Console error shows up when opening emoji picker and then clicking on send button Dec 8, 2023
Copy link

melvin-bot bot commented Dec 8, 2023

Job added to Upwork: https://www.upwork.com/jobs/~017a72f5508e45e17d

Copy link

melvin-bot bot commented Dec 8, 2023

Triggered auto assignment to @strepanier03 (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 Dec 8, 2023
Copy link

melvin-bot bot commented Dec 8, 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

Copy link

melvin-bot bot commented Dec 8, 2023

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

@happy-devs
Copy link

happy-devs commented Dec 8, 2023

Proposal

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

An unescaped method is showing as an console error.

What is the root cause of that problem?

The onCloseCallback method mentioned in the error is in the activePopoverRef.current ref, which may not have it present at the time of being used. This is a quirk of the language where even referencing an endpoint is not safe if it is null, and must be accompanied by an extra clause within the if statement.

const closePopover = React.useCallback((anchorRef?: React.RefObject<HTMLElement>) => {
if (!activePopoverRef.current || (anchorRef && anchorRef !== activePopoverRef.current.anchorRef)) {
return;
}
activePopoverRef.current.close();
if (activePopoverRef.current.onCloseCallback) {
activePopoverRef.current.onCloseCallback();
}
activePopoverRef.current = null;
setIsOpen(false);
}, []);

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

use optional chaining within the if statement to remove or escape the method on current to prevent it from being invoked unless present:

if (activePopoverRef.current?.onCloseCallback) {
            activePopoverRef.current.onCloseCallback();
        }

Some reading material on the issue I've read in the past: https://stackoverflow.com/questions/62603498/optional-chaining-cause-unexpected-result-when-used-in-if-statement

@it-education-md
Copy link

I can't reproduce

@ZhenjaHorbach
Copy link
Contributor

ZhenjaHorbach commented Dec 8, 2023

Proposal

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

Web - Chat - Console error shows up when opening emoji picker and then clicking on send button

What is the root cause of that problem?

The main problem is that we are accessing an empty ref (activePopoverRef.current === null )

And when we try to check this value activePopoverRef.current.onCloseCallback we get error

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

We can update this code like

    const closePopover = React.useCallback((anchorRef?: React.RefObject<HTMLElement>) => {
        if (!activePopoverRef.current || (anchorRef && anchorRef !== activePopoverRef.current.anchorRef)) {
            return;
        }

        const onCloseCallback = lodashGet(activePopoverRef, 'current.onCloseCallback', () => {});
        onCloseCallback();
        activePopoverRef.current.close();
        activePopoverRef.current = null;
        setIsOpen(false);
    }, []);
    

const closePopover = React.useCallback((anchorRef?: React.RefObject<HTMLElement>) => {
if (!activePopoverRef.current || (anchorRef && anchorRef !== activePopoverRef.current.anchorRef)) {
return;
}
activePopoverRef.current.close();
if (activePopoverRef.current.onCloseCallback) {
activePopoverRef.current.onCloseCallback();
}
activePopoverRef.current = null;
setIsOpen(false);
}, []);

What alternative solutions did you explore? (Optional)

NA

@strepanier03
Copy link
Contributor

strepanier03 commented Dec 8, 2023

I can reproduce but I'm not sure of the priority of this. I am raising this internally and will follow up.

@gijoe0295
Copy link
Contributor

gijoe0295 commented Dec 8, 2023

Proposal

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

Console error shows up when opening emoji picker and then clicking on send button.

What is the root cause of that problem?

Short answer

The ref here is null at the time it is invoked.

Long answer

But if that's the case, why didn't the above line activePopoverRef.current.close() fail?

When the popover opens, we bind the callback onClose aka hideEmojiPicker in EmojiPicker component to the close function of the popover ref:

onOpen({
ref: props.withoutOverlayRef,
close: props.onClose,
anchorRef: props.anchorRef,
});

Later when we press Esc, closePopover would be invoked here in which we should care about these lines:

activePopoverRef.current.close();
if (activePopoverRef.current.onCloseCallback) {
activePopoverRef.current.onCloseCallback();
}
activePopoverRef.current = null;

  1. First it runs the ref's close (line 20) and indeed invoke hideEmojiPicker (mentioned above). Later the isVisible prop is changed to false thus invoke the ref's close again here. Note that the previous close call has not finished yet at this moment.
  2. The second invoke of close happens straightforward, without any problem and consequently set the ref to null (line 24)
  3. Now the stack returns to the first close call (mentioned in 1) and continues from line 21. Since the ref was null from 2, it would throw error here.

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

Use optional chaining here:

if (activePopoverRef.current?.onCloseCallback) {
    activePopoverRef.current.onCloseCallback();
}

We should not move the onCloseCallback above close because onCloseCallback is supposed to run after close and that's the purpose of callback functions.

What alternative solutions did you explore? (Optional)

NA

@mkhutornyi
Copy link
Contributor

Proposal

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

Web - Chat - Console error shows up when opening emoji picker and then clicking on send button

What is the root cause of that problem?

const closePopover = React.useCallback((anchorRef?: React.RefObject<HTMLElement>) => {
if (!activePopoverRef.current || (anchorRef && anchorRef !== activePopoverRef.current.anchorRef)) {
return;
}
activePopoverRef.current.close();
if (activePopoverRef.current.onCloseCallback) {
activePopoverRef.current.onCloseCallback();
}
activePopoverRef.current = null;
setIsOpen(false);
}, []);

At first glance, there's no reason for activePopoverRef.current.onCloseCallback being called as already early returns on this line when activePopoverRef.current is null:

if (!activePopoverRef.current || (anchorRef && anchorRef !== activePopoverRef.current.anchorRef)) {

But the issue is in this line:

activePopoverRef.current.close();

This close() function resets reference to null

This is the main root cause

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

change call order like this:

 if (activePopoverRef.current.onCloseCallback) { 
     activePopoverRef.current.onCloseCallback(); 
 } 
 activePopoverRef.current.close(); 

What alternative solutions did you explore? (Optional)

remove all onOpenCallback, onCloseCallback usages throughout the app as they're unused

@hoangzinh
Copy link
Contributor

I can reproduce but I'm not sure of the priority of this. I am raising this internally and will follow up.

@strepanier03 let's us know if we want to fix this issue.

@strepanier03
Copy link
Contributor

I will update as soon as I have an internal consensus, thanks!

@Pujan92
Copy link
Contributor

Pujan92 commented Dec 11, 2023

Proposal

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

Console error for closing the emoji picker

What is the root cause of that problem?

Earlier in this PR we have set the onCloseCallback, onOpenCallback to fix the popover stuck issue. But now it has been removed in the other PR to maintain a list of modals closeModal methods.
closePopover method calls the close method of the activePopoverRef which resets the ref and isVisible state change of Popover also calls the close method again and in that execution activePopoverRef is null which throws the console error.

const closePopover = React.useCallback((anchorRef?: React.RefObject<HTMLElement>) => {
if (!activePopoverRef.current || (anchorRef && anchorRef !== activePopoverRef.current.anchorRef)) {
return;
}
activePopoverRef.current.close();
if (activePopoverRef.current.onCloseCallback) {
activePopoverRef.current.onCloseCallback();
}

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

We can get rid of the onOpenCallback, onCloseCallback fields as it is not needed now as pointed out above due to this PR changes.

@melvin-bot melvin-bot bot added the Overdue label Dec 14, 2023
Copy link

melvin-bot bot commented Dec 15, 2023

@hoangzinh, @strepanier03 Whoops! This issue is 2 days overdue. Let's get this updated quick!

Copy link

melvin-bot bot commented Dec 15, 2023

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

Copy link

melvin-bot bot commented Dec 19, 2023

@hoangzinh, @strepanier03 Still overdue 6 days?! Let's take care of this!

@strepanier03
Copy link
Contributor

All right, we would like to move forward and fix this error.

@melvin-bot melvin-bot bot removed the Overdue label Dec 19, 2023
@strepanier03
Copy link
Contributor

Discussing here still.

@hoangzinh
Copy link
Contributor

@strepanier03 does it mean I can start to review existing proposals or still wait for final call?

@strepanier03
Copy link
Contributor

@hoangzinh - Please pause until next week. I'll update this on the 28th when I'm back in the office.

Copy link

melvin-bot bot commented Dec 22, 2023

@hoangzinh @strepanier03 this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

Copy link

melvin-bot bot commented Jan 29, 2024

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

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Jan 29, 2024
Copy link

melvin-bot bot commented Jan 29, 2024

📣 @hoangzinh 🎉 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

Copy link

melvin-bot bot commented Jan 29, 2024

📣 @mkhutornyi 🎉 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 melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Jan 30, 2024
@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Feb 7, 2024
@melvin-bot melvin-bot bot changed the title [LOW] [$500] Web - Chat - Console error shows up when opening emoji picker and then clicking on send button [HOLD for payment 2024-02-14] [LOW] [$500] Web - Chat - Console error shows up when opening emoji picker and then clicking on send button Feb 7, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Feb 7, 2024
Copy link

melvin-bot bot commented Feb 7, 2024

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

Copy link

melvin-bot bot commented Feb 7, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.37-7 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 2024-02-14. 🎊

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Feb 7, 2024

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:

  • [@hoangzinh] The PR that introduced the bug has been identified. Link to the PR:
  • [@hoangzinh] 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:
  • [@hoangzinh] 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:
  • [@hoangzinh] Determine if we should create a regression test for this bug.
  • [@hoangzinh] 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.
  • [@strepanier03] 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 Overdue and removed Weekly KSv2 labels Feb 13, 2024
@strepanier03
Copy link
Contributor

Looks like we're good until tomorrow. @hoangzinh feel free to finish the checklist and I'll handle the reg test.

@melvin-bot melvin-bot bot removed the Overdue label Feb 13, 2024
@strepanier03
Copy link
Contributor

@mkhutornyi - I've paid you via Upwork and closed the contract, thanks for your help resolving this GH!

@hoangzinh - I'll check later today for the checklist and move forward when it's done.

@hoangzinh
Copy link
Contributor

BugZero Checklist:

@strepanier03
Copy link
Contributor

Got it, thanks @hoangzinh I'll finish this up now.

@strepanier03
Copy link
Contributor

Okay, paid and contract ended. Thanks again for helping to get this finished @hoangzinh and @mkhutornyi 🙌

@strepanier03 strepanier03 changed the title [HOLD for payment 2024-02-14] [LOW] [$500] Web - Chat - Console error shows up when opening emoji picker and then clicking on send button [PAID] [LOW] [$500] Web - Chat - Console error shows up when opening emoji picker and then clicking on send button Feb 15, 2024
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 Engineering External Added to denote the issue can be worked on by a contributor
Projects
Status: CRITICAL
Development

No branches or pull requests