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-02] [$1000] Console error appears when pressing the "Enter" key after zooming in on an image #25953

Closed
1 of 6 tasks
kavimuru opened this issue Aug 25, 2023 · 46 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

@kavimuru
Copy link

kavimuru commented Aug 25, 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 a chat.
  2. Add an attachment.
  3. Select an image and send it.
  4. Open the sent file in preview.
  5. Click the zoom-in button.
  6. Zoom out
  7. Press the Enter key.
  8. Check the console errors.

Expected Result:

Pressing the Enter button after zooming in on an image should not trigger any console errors

Actual Result:

Console error "Uncaught TypeError: Cannot read properties of undefined (reading 'offsetX')" occurs when pressing the Enter button after zooming in on an image

Workaround:

Yes - there is no user impact here

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.57-2
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-08-14-at-102510-pm_9ehB6Ht1.mp4
Recording.1509.mp4

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

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~012ae65e5538e04b44
  • Upwork Job ID: 1696469543815331840
  • Last Price Increase: 2023-09-12
  • Automatic offers:
    • bernhardoj | Contributor | 26743646
@GItGudRatio
Copy link
Contributor

Proposal

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

Console error appears when pressing the "Enter" key after zooming in on an image.

What is the root cause of that problem?

When we open an image and zoom in on it, the image is focused. When we press enter now, the onKeyPressHandler is triggered in GenericPressable. Since the key is enter, we call the onPressHandler with the event. This in turn triggers the onContainerPress function in ImageView. Now, since the KeyboardEvent does not have a nativeEvent, we try to access the value offsetX on a null value, throwing the error.

if (!isZoomed && !isDragging) {
const {offsetX, offsetY} = e.nativeEvent;
// Dividing clicked positions by the zoom scale to get coordinates
// so that once we zoom we will scroll to the clicked location.
const delta = getScrollOffset(offsetX / zoomScale, offsetY / zoomScale);
setZoomDelta(delta);
}
if (isZoomed && isDragging && isMouseDown) {
setIsDragging(false);
setIsMouseDown(false);
} else {
// We first zoom and once its done then we scroll to the location the user clicked.
setIsZoomed(!isZoomed);
setIsMouseDown(false);
}

Since the offsets are calculated only when zooming in, pressing the enter key when already zoomed in does not throw an error.

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

We need to add a conditional such that if !e.nativeEvent or !e.nativeEvent.offsetX or !e.nativeEvent.offsetY, we return from the function.

This is the only occurence of an issue with this root cause.

What alternative solutions did you explore? (Optional)

@kavimuru kavimuru added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Aug 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 25, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Aug 25, 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

@bernhardoj
Copy link
Contributor

Proposal

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

Pressing enter after zooming out an image will throw a console error.

What is the root cause of that problem?

When we click the image to zoom in, the image will now become the focused element. When we press Enter once, it will trigger the onPress callback to zoom out the image. Pressing the Enter again will try to zoom in on the image again, however, using Enter to trigger the onPress will give a KeyboardEvent which doesn't have nativeEvent attribute.

const {offsetX, offsetY} = e.nativeEvent;

So, when we try to destructure the event, it will throw a console error. Both offsetX and offsetY are used to calculate the zoomDelta. The zoomDelta tells how much we should scroll the image horizontally and vertically to focus on the clicked position. See the below video to understand it better.

Screen.Recording.2023-08-26.at.14.49.48.mov

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

In case we press the image with Enter, we can just zoom the image without doing any scrolling.

if (e.nativeEvent) {
    // do the calculation we already have
} else {
    setZoomDelta({offsetX: 0, offsetY: 0});
}

@melvin-bot melvin-bot bot added the Overdue label Aug 28, 2023
@conorpendergrast
Copy link
Contributor

Reviewed, sounds good, let's fix

@melvin-bot melvin-bot bot removed the Overdue label Aug 29, 2023
@conorpendergrast conorpendergrast added the External Added to denote the issue can be worked on by a contributor label Aug 29, 2023
@melvin-bot melvin-bot bot changed the title Console error appears when pressing the "Enter" key after zooming in on an image [$1000] Console error appears when pressing the "Enter" key after zooming in on an image Aug 29, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 29, 2023

Job added to Upwork: https://www.upwork.com/jobs/~012ae65e5538e04b44

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

melvin-bot bot commented Aug 29, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Aug 29, 2023

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

@studentofcoding
Copy link
Contributor

studentofcoding commented Aug 29, 2023

Proposal

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

Pressing enter after zooming out an image will throw a console error.

What is the root cause of that problem?

The error "Uncaught TypeError: Cannot read properties of undefined (reading 'offsetX')" is happening because the code is trying to access the offsetX property of an object that is undefined.

const onContainerPress = (e) => {
if (!isZoomed && !isDragging) {
const {offsetX, offsetY} = e.nativeEvent;
// Dividing clicked positions by the zoom scale to get coordinates
// so that once we zoom we will scroll to the clicked location.
const delta = getScrollOffset(offsetX / zoomScale, offsetY / zoomScale);
setZoomDelta(delta);
}

In the above code, the object is e.nativeEvent in the onContainerPress function. This object is supposed to contain information about the event that triggered the function, including the offsetX property.

Pressing Enter after that will fire a zoom-in, however, using Enter to trigger the onPress isn't a native event

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

The solution is to add a check to ensure that e.nativeEvent is defined and has the necessary properties (offsetX & offsetY) before trying to access them.

const onContainerPress = (e) => {
        if (!isZoomed && !isDragging) {
            if (e.nativeEvent && 'offsetX' in e.nativeEvent && 'offsetY' in e.nativeEvent) {
                const {offsetX, offsetY} = e.nativeEvent;
                const delta = getScrollOffset(offsetX / zoomScale, offsetY / zoomScale);
                setZoomDelta(delta);
            }
        }

Result

Enter.key.no.error.mov

cc: @conorpendergrast @allroundexperts

@melvin-bot melvin-bot bot added the Overdue label Aug 31, 2023
@conorpendergrast
Copy link
Contributor

Some proposals for you here @allroundexperts !

@melvin-bot melvin-bot bot removed the Overdue label Aug 31, 2023
@allroundexperts
Copy link
Contributor

Yep. Will be reviewing soon!

@allroundexperts
Copy link
Contributor

Thanks for your proposal @studentofcoding. However, I'm unable to see how your proposal is different from what @GItGudRatio proposed.

@allroundexperts
Copy link
Contributor

@bernhardoj Is there any case where we might want to zoom without setting a proper zoom delta? If not, then I think @GItGudRatio's proposal should work well.

@bernhardoj
Copy link
Contributor

bernhardoj commented Sep 4, 2023

I think no. If we proceed with @GItGudRatio's proposal, does that mean we only allow user to zoom out but not zoom in with keyboard?

EDIT: actually, depends on where we put the condition, we might disable both zoom in/out with keyboard. Is that what we expected?

@studentofcoding
Copy link
Contributor

studentofcoding commented Sep 4, 2023

I think no. If we proceed with @GItGudRatio's proposal, does that mean we only allow user to zoom out but not zoom in with keyboard?

EDIT: actually, depends on where we put the condition, we might disable both zoom in/out with keyboard. Is that what we expected?

Just for note: In my proposal the Zoom in and out are also managed with Enter Keyboard @bernhardoj @allroundexperts

Also although the RCA is similar, I've detailed the solution & demo of it

@melvin-bot
Copy link

melvin-bot bot commented Sep 5, 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
Copy link

melvin-bot bot commented Sep 11, 2023

@conorpendergrast, @allroundexperts Still overdue 6 days?! Let's take care of this!

@melvin-bot melvin-bot bot added the Overdue label Sep 11, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 11, 2023

@conorpendergrast, @allroundexperts Still overdue 6 days?! Let's take care of this!

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

melvin-bot bot commented Sep 19, 2023

📣 @allroundexperts Please request via NewDot manual requests for the Reviewer role ($1000)

@melvin-bot
Copy link

melvin-bot bot commented Sep 19, 2023

📣 @bernhardoj 🎉 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 19, 2023

📣 @ayazhussain79 We're missing your Upwork ID to automatically send you an offer for the Reporter role.
Once you apply to the Upwork job, your Upwork ID will be stored and you will be automatically hired for future jobs!

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

PR is ready

cc: @allroundexperts

@melvin-bot
Copy link

melvin-bot bot commented Sep 21, 2023

🎯 ⚡️ Woah @allroundexperts / @bernhardoj, 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 @bernhardoj got assigned: 2023-09-19 01:16:34 Z
  • when the PR got merged: 2023-09-21 03:16:03 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 Sep 25, 2023
@melvin-bot melvin-bot bot changed the title [$1000] Console error appears when pressing the "Enter" key after zooming in on an image [HOLD for payment 2023-10-02] [$1000] Console error appears when pressing the "Enter" key after zooming in on an image Sep 25, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Sep 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

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

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 Sep 25, 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:

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

@allroundexperts don't forget about the BZ checklist! ^^

@NicMendonca
Copy link
Contributor

@ayazhussain79 can you please apply to the job? https://www.upwork.com/jobs/~012ae65e5538e04b44

Reporter: @ayazhussain79 - $250
Contributor: @bernhardoj - $1500
C+: @allroundexperts - $1500

@NicMendonca
Copy link
Contributor

@bernhardoj you've been paid! 🎉

@bernhardoj
Copy link
Contributor

@NicMendonca Thanks

@ayazhussain79
Copy link
Contributor

@NicMendonca Applied on upwork, Thank you

@allroundexperts
Copy link
Contributor

Reviewer Checklist

  1. I wasn't able to pinpoint an exact PR which caused this. I think the issue existed from the original implementation.
  2. N/A
  3. Slack discussion is not needed here as this was a missed edge case which could have been caught only by thorough testing.
  4. Regression test would be helpful here.

Regression Test Steps

  1. Open any chat and send an image attachment.
  2. Open the sent image in preview and leftclick on the image to zoom-in.
  3. Left click again to zoom-in and then press the Enter key.

Verify that no error occurs in the console upon pressing the Enter key.

Do we 👍 or 👎 ?

@NicMendonca
Copy link
Contributor

@allroundexperts don't forget to request payment via Expensify!

@ayazhussain79 you've been paid via Upwork!

Payment summary:

Reporter: @ayazhussain79 - $250
Contributor: @bernhardoj - $1500
C+: @allroundexperts - $1500

@JmillsExpensify
Copy link

$1,500 payment approved for @allroundexperts based on BZ summary.

@ayazhussain79
Copy link
Contributor

@NicMendonca Could you kindly end the contract related to this bug on Upwork?

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
None yet
Development

No branches or pull requests

10 participants