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

App crashing in production in some devices when hardware back button is pressed in android #11606

Closed
2 of 11 tasks
androidappteam opened this issue Sep 19, 2023 · 7 comments
Closed
2 of 11 tasks

Comments

@androidappteam
Copy link

androidappteam commented Sep 19, 2023

Current behavior

App crashing in production in some devices when hardware back button is pressed in android

Crash Log from crashlytics

Fatal Exception: t4.c: TypeError: Cannot read property 'key' of undefined, js engine: hermes, stack:
getStateForAction@1:2324604
canGoBack@1:2384972
canGoBack@1:2385008
anonymous@1:2316781
anonymous@1:2382577
anonymous@1:2382518
anonymous@1:2382518
anonymous@1:2316742
anonymous@1:2400742
anonymous@1:328049
emit@1:128838
__callFunction@1:134928
anonymous@1:133434
__guard@1:134374
callFunctionReturnFlushedQueue@1:133392

   at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:72)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
   at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
   at com.facebook.jni.NativeRunnable.run(NativeRunnable.java)
   at android.os.Handler.handleCallback(Handler.java:984)
   at android.os.Handler.dispatchMessage(Handler.java:104)
   at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
   at android.os.Looper.loopOnce(Looper.java:238)
   at android.os.Looper.loop(Looper.java:357)
   at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
   at java.lang.Thread.run(Thread.java:1012)

react-native info
System:
OS: macOS 12.6.1
CPU: (10) arm64 Apple M1 Pro
Memory: 121.75 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.16.0 - /var/folders/c_/kxvkl4wd69z1xdflf_ncr0hjj_bqf_/T/yarn--1695121660525-0.2994264769809307/node
Yarn: 1.22.19 - /var/folders/c_/kxvkl4wd69z1xdflf_ncr0hjj_bqf_/T/yarn--1695121660525-0.2994264769809307/yarn
npm: 8.11.0 - ~/.nvm/versions/node/v16.16.0/bin/npm
Watchman: Not Found
Managers:
CocoaPods: Not Found
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK: Not Found
IDEs:
Android Studio: 2022.3 AI-223.8836.35.2231.10671973
Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.15 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.71.4 => 0.71.4
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Stack trace points to TabRouter.tsx Line 378

const previousKey = state.history[state.history.length - 2].key;

Screenshot 2023-09-19 at 4 39 48 PM

Expected behaviour

App should not crash

Reproduction

We are not able to reproduce this issue in emulator or real device.

Platform

  • Android
  • iOS
  • Web
  • Windows
  • MacOS

Packages

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

Environment

  • [] I've removed the packages that I don't use
package version
@react-navigation/native 6.2.0
@react-navigation/bottom-tabs 6.2.0
@react-navigation/native-stack 6.5.0
react-native-safe-area-context 4.4.1
react-native-screens 3.19.0
react-native 0.71.4
node 16.16.0
npm or yarn 1.22.19
@github-actions
Copy link

Hey @androidappteam! 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

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • @react-navigation/native (found: 6.2.0, latest: 6.1.7)
  • @react-navigation/bottom-tabs (found: 6.2.0, latest: 6.5.8)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

@androidappteam androidappteam changed the title Crashing in production on back press in Android App crashing in production in some devices when hardware back button is pressed in android Sep 19, 2023
@jihoon416
Copy link

I also saw this issue on Crashlytics at work, but was not able to reproduce it on our phones. And sometimes we saw crash logs from our own phones but didnt recall the app crashing visibly.

For reference, our @react-navigation/native is at 6.1.6 and @react-navigation/bottom-tabs at 6.5.7

@github-actions
Copy link

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.

@jihoon416
Copy link

@androidappteam Not sure if it's the same case, but we found out that our problem was due to calling BackHandler.exitApp() and then returning true inside the BackHandler's event listener. We did that to make the user exit the app only when pressing the back button twice (to prevent exiting unwillingly) We changed the event listener to return false and only depend on BackHandler.exitApp() do its job.

@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.

@braandl
Copy link

braandl commented May 16, 2024

This issue still exists in

package version
@react-navigation/native 6.4.16
@react-navigation/bottom-tabs 6.6.15
@react-navigation/native-stack 6.1.17

In Tabrouter.tsx#L389 it checks the previouskey, accessing state.history with state.history.length - 2 as the key and then selects the key from it, without a nullcheck, and here it crashes.

This is triggered from canGoBack that (i understand) is supposed to check if you can actually go back. Therefore I'd consider this a bug.

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

No branches or pull requests

3 participants