react-native: React Native as Fragments crashes when navigate to another React Native Fragment in Android Native app.

Description

Hi,

I do have two tabs that host React Native as fragments in the android kotlin app. I would predictably see the app crashes if I switch between tabs that host React Native fragments. If I just go to one of the tab and not between them, the app functions longer. But it would crash within a few clicks on the tabs after I enter into two tabs that host RN fragments.

Steps to reproduce

  1. run yarn to install all the js dependencies
  2. run yarn start to start the metro server
  3. run yarn android to deploy to the connected android virtual device
  4. click back and forth between the two tabs in the app.
  5. then you would see the app crashes after not more than 10 clicks.

React Native Version

0.73.0

Affected Platforms

Runtime - Android

Output of npx react-native info

System:
  OS: macOS 14.1.2
  CPU: (10) arm64 Apple M1 Max
  Memory: 1.01 GB / 64.00 GB
  Shell:
    version: 3.6.1
    path: /opt/homebrew/bin/fish
Binaries:
  Node:
    version: 21.2.0
    path: /opt/homebrew/opt/node@21/bin/node
  Yarn:
    version: 1.22.21
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.2.4
    path: /opt/homebrew/opt/node@21/bin/npm
  Watchman:
    version: 2023.11.27.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - watchOS 10.0
  Android SDK:
    API Levels:
      - "21"
      - "25"
      - "27"
      - "28"
      - "29"
      - "30"
      - "31"
      - "32"
      - "33"
      - "34"
    Build Tools:
      - 21.1.2
      - 24.0.0
      - 25.0.0
      - 28.0.3
      - 29.0.2
      - 30.0.0
      - 30.0.1
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 32.0.0
      - 33.0.0
      - 33.0.1
      - 34.0.0
    System Images:
      - android-21 | Google APIs ARM 64 v8a
      - android-25 | Google APIs Intel x86 Atom
      - android-27 | Google APIs ARM 64 v8a
      - android-28 | Google APIs Intel x86_64 Atom
      - android-29 | Google Play ARM 64 v8a
      - android-30 | ARM 64 v8a
      - android-31 | Google TV ARM 64 v8a
      - android-32 | Google Play ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
      - android-34 | Google APIs ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
      - android-TiramisuPrivacySandbox | Google APIs ARM 64 v8a
      - android-UpsideDownCakePrivacySandbox | Google Play ARM 64 v8a
    Android NDK: 22.1.7171670
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11076708
  Xcode:
    version: 15.0.1/15A507
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 18.0.2.1
    path: /Users/watt/.jenv/shims/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.0
    wanted: ^0.73.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: false

Stacktrace or Logs

Process: com.playground.internal, PID: 20145
                                                                                                    java.lang.AssertionError
                                                                                                    	at com.facebook.infer.annotation.Assertions.assertCondition(Assertions.java:82)
                                                                                                    	at com.facebook.react.ReactInstanceManager.onHostPause(ReactInstanceManager.java:581)
                                                                                                    	at com.facebook.react.ReactDelegate.onHostPause(ReactDelegate.java:107)
                                                                                                    	at com.facebook.react.ReactFragment.onPause(ReactFragment.java:110)
                                                                                                    	at androidx.fragment.app.Fragment.performPause(Fragment.java:3330)
                                                                                                    	at androidx.fragment.app.FragmentStateManager.pause(FragmentStateManager.java:684)
                                                                                                    	at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:310)
                                                                                                    	at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2088)
                                                                                                    	at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1970)
                                                                                                    	at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1925)
                                                                                                    	at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:643)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:958)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:205)
                                                                                                    	at android.os.Looper.loop(Looper.java:294)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8177)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

Reproducer

https://github.com/wpoosanguansit/internal

Screenshots and Videos

Screen Recording 2023-12-08 at 12 34 00 PM

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 16 (4 by maintainers)

Most upvoted comments

Thank you. I have been waiting for this. I will definitely try it out. Thanks again for your help.

On Oct 7, 2024, at 7:25 AM, Nicola Corti @.***> wrote:

If there is anything that I can do to have this issue resolved, I will more than glad. Thanks!

I’ve recently rewritten the docs for integration with Fragments: https://reactnative.dev/docs/next/integration-with-android-fragment

So please make sure you follow the reccomended APIs (i.e. use ReactApplication and ReactFragment).

Plus, I see that your crash is happening on the Old Architecture, which we’re not actively developing anymore. If you follow the new guides, the integration will work with both architectures so I’d suggest you take a look at them.

— Reply to this email directly, view it on GitHub https://github.com/facebook/react-native/issues/41850#issuecomment-2397082559, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAWE3KWE7VQXPBVMIAKOGTZ2KKT3AVCNFSM6AAAAABPN7EQGOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJXGA4DENJVHE. You are receiving this because you authored the thread.

This issue no longer happens on my end.

Yes. And I upgraded in between trying to fix the issue.On Dec 9, 2023, at 12:11 AM, Nicola Corti @.***> wrote:

And with those, we will still see the crash. Thanks for your help.

So you had the crash in 0.72 also?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>