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-12-26] [$500] Dev: Web - Console error in modal route navigation #31487

Closed
1 of 6 tasks
kbecciv opened this issue Nov 17, 2023 · 31 comments
Closed
1 of 6 tasks
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

@kbecciv
Copy link

kbecciv commented Nov 17, 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: Dev 1.4.0
Reproducible in staging?: n
Reproducible in production?: n
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: @allroundexperts
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1700217148936209

Action Performed:

  1. Go to NewDot
  2. Log in with any account
  3. Navigate to any modal route

Expected Result:

No console error in modal route navigation

Actual Result:

Console error in modal route navigation

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

Screenshot 2023-11-17 at 3 32 09 PM

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01cb7a8b97975fcd6d
  • Upwork Job ID: 1725501903376543744
  • Last Price Increase: 2023-11-24
  • Automatic offers:
    • ntdiary | Reviewer | 27849866
    • dukenv0307 | Contributor | 27849868
@kbecciv kbecciv 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 Nov 17, 2023
@melvin-bot melvin-bot bot changed the title Dev: Web - Console error in modal route navigation [$500] Dev: Web - Console error in modal route navigation Nov 17, 2023
Copy link

melvin-bot bot commented Nov 17, 2023

Job added to Upwork: https://www.upwork.com/jobs/~01cb7a8b97975fcd6d

Copy link

melvin-bot bot commented Nov 17, 2023

Triggered auto assignment to @bfitzexpensify (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 Nov 17, 2023
Copy link

melvin-bot bot commented Nov 17, 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 Nov 17, 2023

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

@aimane-chnaif
Copy link
Contributor

cc: @getusha

@dukenv0307
Copy link
Contributor

dukenv0307 commented Nov 17, 2023

Proposal

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

Console error in modal route navigation

What is the root cause of that problem?

We're not using the latest version of "react-navigation/native", the old version still uses BackHandler in web

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

Upgrate "react-navigation/native" to latest (or the whole react-navigation

This issue has been fixed there via this commit

What alternative solutions did you explore? (Optional)

Only add the code that fixes the issue as a patch. The library upgrade can be later since I assume we might have a plan for that.

@PiyushChandra17
Copy link

PiyushChandra17 commented Nov 17, 2023

Proposal

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

Console error in modal route navigation

What is the root cause of that problem?

We are using backHandler and it's only supported in native android devices for going back, this is the root cause.

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

We need to apply following changes:

  • import Platform module from react-native
  • If the platform is web, then we should use useNavigation hook from react navigation
  • Initialize the useNavigation hook
  • Apply navigation.goBack()

What alternative solutions did you explore? (Optional)

NA

@jeet-dhandha
Copy link
Contributor

Proposal

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

  • We are getting console error for BackHandler on web.

What is the root cause of that problem?

  • We are getting console error due to use of useNavigation hook as it uses useBackButton hook internally.
  • And useBackButton hook uses BackHandler which is not available in web.
  • So we need to disable useBackButton hook on web.

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

  • We can add below code at eod in our @react-navigation+native+6.1.6.patch file to disable useBackButton hook on web.
diff --git a/node_modules/@react-navigation/native/lib/module/useBackButton.js b/node_modules/@react-navigation/native/lib/module/useBackButton.js
index e016a69a1..1903b148a 100644
--- a/node_modules/@react-navigation/native/lib/module/useBackButton.js
+++ b/node_modules/@react-navigation/native/lib/module/useBackButton.js
@@ -1,6 +1,7 @@
 import * as React from 'react';
-import { BackHandler } from 'react-native';
+import { BackHandler, Platform } from 'react-native';
 export default function useBackButton(ref) {
+  if(Platform.OS === 'web') return;
   React.useEffect(() => {
     const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
       const navigation = ref.current;
\ No newline at end of file
  • One enchancement we can do is update my patch to use code from react-native-modal+13.0.1.patch which adds a escape key handler for web.
  • + if (Platform.OS === 'web') {
    + document?.body?.addEventListener?.('keyup', this.handleEscape, true);
    + return;
    + }

What alternative solutions did you explore? (Optional)

  • We can upgrade our package to latest 6.x version. But it will probably require changes in our patches and codebase.

@melvin-bot melvin-bot bot added the Overdue label Nov 20, 2023
@bfitzexpensify
Copy link
Contributor

Adding engineering just to confirm this is reproducible since it's a dev error.

Copy link

melvin-bot bot commented Nov 20, 2023

Triggered auto assignment to @arosiclair (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

@melvin-bot melvin-bot bot removed the Overdue label Nov 20, 2023
@arosiclair
Copy link
Contributor

@bfitzexpensify I reproduced 👍

Screenshot 2023-11-21 at 10 45 55 AM

@bfitzexpensify
Copy link
Contributor

Great. @ntdiary, looks like we've got a few proposals ready for review.

@abdullahbinahmed
Copy link

abdullahbinahmed commented Nov 22, 2023

Proposal

from: @abdullahbinahmed

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

Backhandler is not supported for the web and is being called by React Modal so we are getting the error on the Web in console.

What is the root cause of that problem?

BackHandler is imported in web code but is not part of the react-native-web API (0.19) anymore.

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

Backhandler is not present for web code as mentioned above so if the website is being accessed by the user from the web interface, we should detect it and not call backhandler for it.
This issue has been raised in react-navigation repo here
So my solution is the solution that have been tested and merged in the main branch by the developer of react-navigation.The link to fix here

import type {
  NavigationContainerRef,
  ParamListBase,
} from '@react-navigation/core';
import * as React from 'react';
import { BackHandler, Platform } from 'react-native';

export default function useBackButton(
  ref: React.RefObject<NavigationContainerRef<ParamListBase>>
) {
  const handleEscape = (event) => {
    if (event.key === 'Escape') {
      const navigation = ref.current;
      if (navigation && navigation.canGoBack()) {
        navigation.goBack();
      }
    }
  };
  if (Platform.OS === 'web') {
    document?.body?.addEventListener?.('keyup', handleEscape);
    return () => {
      document?.body?.removeEventListener?.('keyup', handleEscape);
    };
  }
  React.useEffect(() => {
    const subscription = BackHandler.addEventListener(
      'hardwareBackPress',
      () => {
        const navigation = ref.current;

        if (navigation == null) {
          return false;
        }

        if (navigation.canGoBack()) {
          navigation.goBack();

          return true;
        }

        return false;
      }
    );

    return () => subscription?.remove?.();
  }, [ref]);
}

The patch would be created as a solution as follows:

--- node_modules/@react-navigation/native/src/useBackButton.tsx	2023-11-22 10:59:35.340000000 +0500
+++ test.js	2023-11-22 11:17:35.370000000 +0500
@@ -3,11 +3,25 @@
   ParamListBase,
 } from '@react-navigation/core';
 import * as React from 'react';
-import { BackHandler } from 'react-native';
+import { BackHandler, Platform } from 'react-native';
 
 export default function useBackButton(
   ref: React.RefObject<NavigationContainerRef<ParamListBase>>
 ) {
+  const handleEscape = (event) => {
+    if (event.key === 'Escape') {
+      const navigation = ref.current;
+      if (navigation && navigation.canGoBack()) {
+        navigation.goBack();
+      }
+    }
+  };
+  if (Platform.OS === 'web') {
+    document?.body?.addEventListener?.('keyup', handleEscape);
+    return () => {
+      document?.body?.removeEventListener?.('keyup', handleEscape);
+    };
+  }
   React.useEffect(() => {
     const subscription = BackHandler.addEventListener(
       'hardwareBackPress',
@@ -28,6 +42,6 @@
       }
     );
 
-    return () => subscription.remove();
+    return () => subscription?.remove?.();
   }, [ref]);
 }

The idea behind the solution is we only add the listeners when users tries to go back. This way we can make sure that the listener is added as late as possible. This will make sure that our handler will run first when back button is pressed.

What alternative solutions did you explore? (Optional)

We cannot update the version of the package as this fix is not included in a version release yet so we have to create a patch file for this issue.

Copy link

melvin-bot bot commented Nov 22, 2023

📣 @abdullahbinahmed! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
    Screen Shot 2022-11-16 at 4 42 54 PM
    Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

@abdullahbinahmed
Copy link

Contributor details
Your Expensify account email: smabdullah.binahmed@gmail.com
Upwork Profile Link: https://www.upwork.com/freelancers/smabdullahahmed

Copy link

melvin-bot bot commented Nov 22, 2023

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

@ntdiary
Copy link
Contributor

ntdiary commented Nov 22, 2023

@bfitzexpensify I reproduced 👍

Screenshot 2023-11-21 at 10 45 55 AM

Hi, @arosiclair, is this the error you see when opening the app or refreshing the app? If so, we had a similar issue #31120 before, and the final decision was to close that issue and wait for the upgrade.
As for the expected behavior mentioned in the OP, if the react-native-modal+13.0.1.patch is successfully applied, opening any modal should no longer print this error.

cc @bfitzexpensify

@ntdiary
Copy link
Contributor

ntdiary commented Nov 23, 2023

Okay it sounds like we should upgrade. The version linked in that issue was an alpha release. Has that been put in any stable release?

@arosiclair, sure, the latest fix code has been included in the v6.1.8.

image

Copy link

melvin-bot bot commented Nov 24, 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 Nov 27, 2023
@arosiclair
Copy link
Contributor

Okay looks like that is @dukenv0307's original proposal. Let's go ahead and upgrade that package.

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

melvin-bot bot commented Nov 27, 2023

📣 @ntdiary 🎉 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 Nov 27, 2023

📣 @dukenv0307 🎉 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 📖

Copy link

melvin-bot bot commented Nov 27, 2023

📣 @allroundexperts Please request via NewDot manual requests for the Reporter role ($50)

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Nov 28, 2023
@dukenv0307
Copy link
Contributor

@ntdiary The PR is ready for review.

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Dec 19, 2023
@melvin-bot melvin-bot bot changed the title [$500] Dev: Web - Console error in modal route navigation [HOLD for payment 2023-12-26] [$500] Dev: Web - Console error in modal route navigation Dec 19, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Dec 19, 2023
Copy link

melvin-bot bot commented Dec 19, 2023

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

Copy link

melvin-bot bot commented Dec 19, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.13-8 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-12-26. 🎊

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:

Copy link

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

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

Payments finalised, @ntdiary please complete the BZ checklist when you get a moment - thanks!

@ntdiary
Copy link
Contributor

ntdiary commented Dec 27, 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:

  • [@ntdiary] The PR that introduced the bug has been identified. Link to the PR: Upgrade to react-native-web v0.19.9 #24482
  • [@ntdiary] 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: Upgrade to react-native-web v0.19.9 #24482 (comment)
  • [@ntdiary] 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: No need
  • [@ntdiary] Determine if we should create a regression test for this bug. No need
  • [@ntdiary] 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. No need
  • [@bfitzexpensify] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

This error is actually caused by api changes of react-native-web. It's fine to just upgrade the versions of other libraries that depend on the react-native-web, and there's no need to create a regression test. :)

@bfitzexpensify
Copy link
Contributor

Thanks @ntdiary, agreed - let's close this out

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

9 participants