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-08-08] [$1000] Web - App crashes after pressing Backspace/Delete key in Incorrect magic code page #23596

Closed
1 of 6 tasks
kbecciv opened this issue Jul 25, 2023 · 44 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

@kbecciv
Copy link

kbecciv commented Jul 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. On login page, enter an email/phone number and click Continue
  2. Enter WRONG Magic code
  3. When the error is showing, hold the left-mouse button and drag over the Magic code field - (like we are selecting text BUT do not show the selection)
  4. Press Backspace/Delete key on the keyboard

Expected Result:

Application should not crash

Actual Result:

Application crashes

Workaround:

Unknown

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.45-1
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

CRASH.mp4
Recording.3910.mp4

Expensify/Expensify Issue URL:
Issue reported by: @tranvantoan-qn
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1690254789469459

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~017414e8528c6cdd44
  • Upwork Job ID: 1684228115617501184
  • 2023-07-26
  • Automatic offers:
    • s77rt | Reviewer | 25775610
    • Pujan92 | Contributor | 25775614
    • tranvantoan-qn | Reporter | 25775617
@kbecciv kbecciv added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jul 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 25, 2023

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

@melvin-bot
Copy link

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

@kbecciv
Copy link
Author

kbecciv commented Jul 25, 2023

Proposal: @tranvantoan-qn
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1690254789469459

Proposal

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

App crashes after pressing Backspace/Delete key in Incorrect magic code page

What is the root cause of that problem?

After dragging, the editIndex will be undefined, making it unable to retrieve the object. Unfortunately, in the following code, we did not check for this scenario, which results in an app crash:
https://github.com/Expensify/App/blob/main/src/components/MagicCodeInput.js#L105

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

To prevent the crash, add the following condition:

        if (inputRefs.current[editIndex]) { 
            inputRefs.current[editIndex].blur();    
        }

@huzaifa-99
Copy link
Contributor

huzaifa-99 commented Jul 26, 2023

Proposal

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

We want the app to not crash when backspace key is pressed on the magic code input (after drag select)

What is the root cause of that problem?

When we submit the form (it happens when we fill the last cell of input), then we set the focused index to undefined here.

And next, when we drag over the whole input, the focus event gets triggered, but we don't update the focused and edit index in that event. And next, when we press backspace, the focused index will still be undefined which causes the editIndex to also become undefined, and on blur, this undefined editIndex crashes the app.

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

I think we should use a single type for focusedIndex, and not use undefined (we can add -1 in place of that). This is important because eventually, we will be moving to typescript.

So when we blur the input we should set the focused index to -1 here.

And on focus event, when focusedIndex is -1, we update the focused index to the current cell index like this

if (focusedIndex == -1) {
    setInput('');
    setEditIndex(index)
    setFocusedIndex(index)
}

and we update the focus event of text input like this

onFocus={(event) => onFocus(event, index)}

Now when backspace is pressed, the focusedIndex will be properly defined.

I used -1 to indicate that no cell is focused, we can use any other number value here

Focus event triggers before the press event. We can optimize the state updates in this case

What alternative solutions did you explore? (Optional)

Block the drag selection on the magic code input

@CortneyOfstad CortneyOfstad added the External Added to denote the issue can be worked on by a contributor label Jul 26, 2023
@melvin-bot melvin-bot bot changed the title Web - App crashes after pressing Backspace/Delete key in Incorrect magic code page [$1000] Web - App crashes after pressing Backspace/Delete key in Incorrect magic code page Jul 26, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 26, 2023

Job added to Upwork: https://www.upwork.com/jobs/~017414e8528c6cdd44

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

melvin-bot bot commented Jul 26, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Jul 26, 2023

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

@CortneyOfstad
Copy link
Contributor

@s77rt we have a couple of proposals for your review above 👍 TIA!

@Pujan92
Copy link
Contributor

Pujan92 commented Jul 26, 2023

Proposal

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

App crashes when we press Backspace/Delete after dragging the mouse from input box

What is the root cause of that problem?

Once magic code has been fulfilled, we called blurMagicCodeInput which will set the focused index to undefined. It seems when we start dragging from the input box, it will execute the focus event of the text where we aren't setting the index which we are doing within onPress callback. As the dragged Text input is focused it will fire the onKeyPress when we press Backspace and that is causing the issue of calling the blur method on undefined.

const onFocus = (event) => {
event.preventDefault();
};

const onPress = (event, index) => {
event.preventDefault();
setInput('');
setFocusedIndex(index);
setEditIndex(index);
};

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

We can remove onPress and shift its logic to onFocus method where we perform the below steps which will set the correct index when the drag starts with the input box. As onFocus will be responsible for setting the indexes(focus & edit), we can take advantage of it and remove the same indexes setting code parts from onKeyPress.

setInput('');
setFocusedIndex(index);
setEditIndex(index);

@s77rt
Copy link
Contributor

s77rt commented Jul 26, 2023

@tranvantoan-qn Thanks for the proposal. I don't think your RCA is correct.

After dragging, the editIndex will be undefined

This does not seem to be the case, dragging does not affect the editIndex.

@s77rt
Copy link
Contributor

s77rt commented Jul 26, 2023

@huzaifa-99 Thanks for the proposal. Your RCA is not exactly right.

when we drag over the whole input (important: without focusing any cell) ... and on blur

This is a contradiction, if the blur event occurs then the input is actually focused. The root cause here seems to be that even the input is actually focused we don't update the MagicCodeInput with such info.

@tranvantoan-qn
Copy link

tranvantoan-qn commented Jul 26, 2023

@s77rt

It actually does in this case - please note that even though we were dragging, in order to see the crash the text selection must not be shown (dragging but no text selection sounds weird, but it happened in this case 😄)

  • See my video at 0:03 or 0:10 where I started holding the left-mouse button and dragging
CRASH.mp4

The issue won't happen if the text selection is showing like this:
Explain

@s77rt
Copy link
Contributor

s77rt commented Jul 26, 2023

@Pujan92 Thanks for the proposal. Your RCA is the most correct here.

It seems when we start dragging from the input box, it will execute the focus event of the text but we aren't setting the index (focus index / edit index)

Your solution makes sense but I'm afraid it causes a regression (similar to an old bug):

  1. Start typing magic code
  2. Switch tab
  3. Back to tab
  4. Notice the position of the input did change
Kooha-2023-07-26-20-03-43.mp4

@tranvantoan-qn
Copy link

tranvantoan-qn commented Jul 26, 2023

My question with his solution is: If the issue is caused by the onKeyPress event, why did the crash only happen with Backspace or Delete key? and as mentioned "Crash happens only when the text selection is not showing" - so what should be the value for focus index/edit index

@s77rt
Copy link
Contributor

s77rt commented Jul 26, 2023

@tranvantoan-qn Thanks for the update, but I still don't think this is the root cause. The root cause is that when you try to drag, onMouseDown you will focus the input. But we don't take that focus event into account i.e. MagicCodeInput still thinks that no input is focused (focusedIndex is still undefined). Then the blur event will occur and MagicCodeInput will blur the input that it has but it does not have the correct values for focusedIndex and editIndex.

@s77rt
Copy link
Contributor

s77rt commented Jul 26, 2023

@tranvantoan-qn

Crash only happens when text selection is not showing because in that case the text input won't be focused. You can verify and type document.activeElement in the console. Notice that the issue will only happen if the activeElement is the text input.

@huzaifa-99
Copy link
Contributor

huzaifa-99 commented Jul 26, 2023

@s77rt Thank you for the review, how about we add this condition to the focus event

 if (focusedIndex == -1) {
            setInput('');
            setEditIndex(index)
            setFocusedIndex(index)
}

Updating my proposal....

@huzaifa-99
Copy link
Contributor

@s77rt I have updated my proposal

@s77rt
Copy link
Contributor

s77rt commented Jul 26, 2023

@huzaifa-99 How would that fix the root cause? We need to ensure the following:
As long as the input is focused i.e. as long as document.activeElement return a text input (from the magic input). The state focusedIndex should have the index of that input and not undefined.

The below image shows a scenario that should never exist
Screenshot from 2023-07-26 20-26-44

@tranvantoan-qn
Copy link

tranvantoan-qn commented Jul 26, 2023

@s77rt Following your explanation, I saw that the activeElement is always pointed to the last field >> so it means editIndex should have that field's index?
image

@huzaifa-99
Copy link
Contributor

huzaifa-99 commented Jul 26, 2023

The root cause here seems to be that even the input is actually focused we don't update the MagicCodeInput with such info.
@huzaifa-99 How would that fix the root cause? We need to ensure the following:
As long as the input is focused i.e. as long as document.activeElement return a text input (from the magic input). The state focusedIndex should have the index of that input and not undefined.

@s77rt whenever the input is focused, the onFocus is guaranteed to be triggered. When we start to drag over the inputs (important: without pressing on them), the input we drag from becomes focused ex: lets say we drag from the 5th cell, 5th cell will get focused, and this triggers the focus event. In my updated proposal, this is how the onFocus looks like, so whenever input gets focused we will check if no cell is focused i.e focusedIndex == -1 and set state accordingly

const onFocus = (event, index) => {
    event.preventDefault();

    if (focusedIndex == -1) {
        setInput('');
        setEditIndex(index)
        setFocusedIndex(index)
    }
};

In this demo, i drag from the last input and state updates correctly on focus

Screen.Recording.2023-07-27.at.12.47.46.AM.mp4

@Pujan92
Copy link
Contributor

Pujan92 commented Jul 26, 2023

Your solution makes sense but I'm afraid it causes a regression (similar to an old bug):

  1. Start typing magic code
  2. Switch tab
  3. Back to tab
  4. Notice the position of the input did change

@s77rt I think it is bcoz on changing the text we are not actually focusing on those input boxes. For that, we do need to use inputRefs.current[updatedFocusedIndex].focus(); by replacing this code here.

setFocusedIndex(updatedFocusedIndex);
setInput(value);

Screen.Recording.2023-07-27.at.2.16.45.AM.mp4

@s77rt
Copy link
Contributor

s77rt commented Jul 26, 2023

@huzaifa-99 I don't see how this is different than @Pujan92's proposal. Also there is no reason to add the focusedIndex == -1 check.

@melvin-bot melvin-bot bot added the Weekly KSv2 label Jul 27, 2023
@Pujan92
Copy link
Contributor

Pujan92 commented Jul 27, 2023

@s77rt PR is ready for review!

@melvin-bot
Copy link

melvin-bot bot commented Jul 28, 2023

🎯 ⚡️ Woah @s77rt / @Pujan92, 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 @Pujan92 got assigned: 2023-07-27 00:00:39 Z
  • when the PR got merged: 2023-07-28 17:38:20 UTC

On to the next one 🚀

@CortneyOfstad
Copy link
Contributor

I'm heading OoO until 8/14, so reassigning BZ to keep an eye on it while I'm out 👍

@CortneyOfstad CortneyOfstad removed their assignment Aug 1, 2023
@CortneyOfstad CortneyOfstad added Bug Something is broken. Auto assigns a BugZero manager. and removed Bug Something is broken. Auto assigns a BugZero manager. labels Aug 1, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 1, 2023

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

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Aug 1, 2023
@melvin-bot
Copy link

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

@CortneyOfstad CortneyOfstad self-assigned this Aug 1, 2023
@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Daily KSv2 labels Aug 1, 2023
@melvin-bot melvin-bot bot changed the title [$1000] Web - App crashes after pressing Backspace/Delete key in Incorrect magic code page [HOLD for payment 2023-08-08] [$1000] Web - App crashes after pressing Backspace/Delete key in Incorrect magic code page Aug 1, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Aug 1, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 1, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Aug 1, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.48-5 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-08-08. 🎊

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 Aug 1, 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:

  • [@s77rt] The PR that introduced the bug has been identified. Link to the PR:
  • [@s77rt] 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:
  • [@s77rt] 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:
  • [@s77rt] Determine if we should create a regression test for this bug.
  • [@s77rt] 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.
  • [@JmillsExpensify / @CortneyOfstad] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@s77rt
Copy link
Contributor

s77rt commented Aug 3, 2023

@melvin-bot melvin-bot bot added Daily KSv2 Overdue and removed Weekly KSv2 labels Aug 8, 2023
@CortneyOfstad
Copy link
Contributor

I am back from OoO, so taking this back over. Thanks @s77rt for the review above!

@melvin-bot melvin-bot bot removed the Overdue label Aug 14, 2023
@CortneyOfstad
Copy link
Contributor

Payments have been made!

@tranvantoan-qn was paid the reporting amount of $250
@Pujan92 and @s77rt were both paid $1,500 (contributor and C+ fee, plus bonus due to the PR being merged within 1 day of assignment).

Closing!

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

8 participants