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

Don't use BackHandler in web code paths #11316

Closed
1 of 5 tasks
necolas opened this issue Apr 3, 2023 · 9 comments · Fixed by #11458
Closed
1 of 5 tasks

Don't use BackHandler in web code paths #11316

necolas opened this issue Apr 3, 2023 · 9 comments · Fixed by #11458

Comments

@necolas
Copy link

necolas commented Apr 3, 2023

Current behavior

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

Expected behavior

BackHandler should not be used in web code paths. BackHandler can only be imported from react-native for native platforms, and file extension forks should be used to prevent import { BackHandler } from 'react-native' from being present in web code.

Reproduction

n/a. No repro because snack doesn't use the latest versions of the react libraries.

Platform

  • Android
  • iOS
  • Web
  • Windows
  • MacOS
@github-actions
Copy link

github-actions bot commented Apr 3, 2023

Hey @necolas! Thanks for opening the issue. It seems that the issue doesn't contain a link to a repro.

The best way to get attention to your issue is to provide an easy way for a developer to reproduce the issue.

You can provide a repro using any of the following:

A snack link is preferred since it's the easiest way to both create and share a repro. If it's not possible to create a repro using a snack, link to a GitHub repo under your username is a good alternative. Don't link to a branch or specific file etc. as it won't be detected.

Try to keep the repro as small as possible by narrowing down the minimal amount of code needed to reproduce the issue. Don't link to your entire project or a project containing code unrelated to the issue. See "How to create a Minimal, Reproducible Example" for more information.

You can edit your original issue to include a link to the repro, or leave it as a comment. The issue will be closed automatically after a while if you don't provide a repro.

@github-actions
Copy link

github-actions bot commented Apr 3, 2023

Couldn't find version numbers for the following packages in the issue:

  • @react-navigation/native
  • @react-navigation/bottom-tabs
  • @react-navigation/drawer
  • @react-navigation/material-top-tabs
  • @react-navigation/stack
  • react-native-tab-view

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

@github-actions
Copy link

github-actions bot commented Apr 3, 2023

Couldn't find version numbers for the following packages in the issue:

  • @react-navigation/native

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

@agusvazquez
Copy link

agusvazquez commented Apr 4, 2023

BackHandler got removed on react-native-web here by @necolas
https://github.com/necolas/react-native-web/pull/2377/files#diff-7b7290df21d2dbbc4a5f367f43fb9d8beacd84c6b4ea693ccec2265d2e212404

He broke the main purpose of the library that is to provide compatibility with react native platform, and now he expects everyone coding for react native (not web) to fix that on external libs.

BackHandler is not deprecated on RN https://reactnative.dev/docs/backhandler.

This is another library that is not working well with RN web and there will be plenty of them
https://github.com/expo/react-native-action-sheet

Please rollback, thanks!

More info here.
necolas/react-native-web#2377
necolas/react-native-web#2504

@github-actions
Copy link

github-actions bot commented May 5, 2023

Hello 👋, this issue has been open for more than a month without a repro or any activity. If the issue is still present in the latest version, please provide a repro or leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution or workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix it.

@Acetyld
Copy link

Acetyld commented May 23, 2023

Any update on this?
For now a patch-package

diff --git a/node_modules/react-native-web/dist/cjs/exports/BackHandler/index.js b/node_modules/react-native-web/dist/cjs/exports/BackHandler/index.js
index 24ebcd8..aa26374 100644
--- a/node_modules/react-native-web/dist/cjs/exports/BackHandler/index.js
+++ b/node_modules/react-native-web/dist/cjs/exports/BackHandler/index.js
@@ -16,7 +16,6 @@ function emptyFunction() {}
 var BackHandler = {
   exitApp: emptyFunction,
   addEventListener() {
-    console.error('BackHandler is not supported on web and should not be used.');
     return {
       remove: emptyFunction
     };
diff --git a/node_modules/react-native-web/dist/exports/BackHandler/index.js b/node_modules/react-native-web/dist/exports/BackHandler/index.js
index 13f044d..ae8ed17 100644
--- a/node_modules/react-native-web/dist/exports/BackHandler/index.js
+++ b/node_modules/react-native-web/dist/exports/BackHandler/index.js
@@ -12,7 +12,6 @@ function emptyFunction() {}
 var BackHandler = {
   exitApp: emptyFunction,
   addEventListener() {
-    console.error('BackHandler is not supported on web and should not be used.');
     return {
       remove: emptyFunction
     };
diff --git a/node_modules/react-native-web/dist/exports/BackHandler/index.js.flow b/node_modules/react-native-web/dist/exports/BackHandler/index.js.flow
index 1523698..347b533 100644
--- a/node_modules/react-native-web/dist/exports/BackHandler/index.js.flow
+++ b/node_modules/react-native-web/dist/exports/BackHandler/index.js.flow
@@ -13,7 +13,6 @@ const BackHandler = {
   addEventListener(): {|
     remove: () => void
   |} {
-    console.error('BackHandler is not supported on web and should not be used.');
     return {
       remove: emptyFunction
     };
diff --git a/node_modules/react-native-web/src/exports/BackHandler/index.js b/node_modules/react-native-web/src/exports/BackHandler/index.js
index 205fc58..69557f6 100644
--- a/node_modules/react-native-web/src/exports/BackHandler/index.js
+++ b/node_modules/react-native-web/src/exports/BackHandler/index.js
@@ -13,9 +13,6 @@ function emptyFunction() {}
 const BackHandler = {
   exitApp: emptyFunction,
   addEventListener(): {| remove: () => void |} {
-    console.error(
-      'BackHandler is not supported on web and should not be used.'
-    );
     return {
       remove: emptyFunction
     };

@mlennie
Copy link

mlennie commented Jul 19, 2023

@EvanBacon any update on this? I just tried deploying to firebase and I'm getting the same issue
Screenshot 2023-07-18 at 7 52 02 PM

kacperkapusciak pushed a commit that referenced this issue Jul 31, 2023
kacperkapusciak pushed a commit that referenced this issue Jul 31, 2023
@Gregoor
Copy link

Gregoor commented Sep 22, 2023

Is there a 6.x release for this fix planned or only 7.x? I'm wondering because this seems to be blocking my expo-router adoption (in conjunction with react-native-web)

@github-actions
Copy link

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants