software-mansion / react-native-screens

Native navigation primitives for your React Native app.
https://docs.swmansion.com/react-native-screens/
MIT License
3.02k stars 511 forks source link

Android couldn't found for fragment (Fabric only) #1762

Open Bort-777 opened 1 year ago

Bort-777 commented 1 year ago

Description

Hello,

I have experienced an app crash while navigating between bottom tabs multiple times. I have attached the stacktrace and a repro example for reference. The issue may be related to https://github.com/react-navigation/react-navigation/issues/11165. Please take a look and let me know if you could advise.

Thank you.

java.lang.IllegalArgumentException: No view found for id 0x646 (unknown) for fragment ScreenFragment{34a3771} (f38da73b-6497-4306-a70a-402ae94cea5f id=0x646)

FATAL EXCEPTION: main
Process: com.app, PID: 5488
java.lang.IllegalArgumentException: No view found for id 0x646 (unknown) for fragment ScreenFragment{34a3771} (f38da73b-6497-4306-a70a-402ae94cea5f id=0x646)
    at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:513)
    at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)
    at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1840)
    at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1764)
    at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1670)
    at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:323)
    **at com.swmansion.rnscreens.ScreenContainer.onUpdate(ScreenContainer.kt:366)**
    at com.swmansion.rnscreens.ScreenContainer.performUpdates(ScreenContainer.kt:311)
    at com.swmansion.rnscreens.ScreenContainer.performUpdatesNow(ScreenContainer.kt:303)
    at com.swmansion.rnscreens.ScreenContainer.setFragmentManager(ScreenContainer.kt:127)
    at com.swmansion.rnscreens.ScreenContainer.setupFragmentManager(ScreenContainer.kt:180)
    at com.swmansion.rnscreens.ScreenContainer.onAttachedToWindow(ScreenContainer.kt:217)
    at android.view.View.dispatchAttachedToWindow(View.java:20107)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3619)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3626)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3626)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3626)
    at android.view.ViewGroup.addViewInner(ViewGroup.java:5404)
    at android.view.ViewGroup.addView(ViewGroup.java:5190)
    at android.view.ViewGroup.addView(ViewGroup.java:5130)
    at androidx.fragment.app.FragmentStateManager.addViewToContainer(FragmentStateManager.java:839)
    at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:528)
    at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)
    at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1840)
    at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1764)
    at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1670)
    at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:323)
    at com.swmansion.rnscreens.ScreenContainer.onUpdate(ScreenContainer.kt:366)
    at com.swmansion.rnscreens.ScreenContainer.performUpdates(ScreenContainer.kt:311)
    at com.swmansion.rnscreens.ScreenContainer.performUpdatesNow(ScreenContainer.kt:303)
    at com.swmansion.rnscreens.ScreenContainer.notifyChildUpdate(ScreenContainer.kt:87)
    at com.swmansion.rnscreens.Screen.setActivityState(Screen.kt:132)
    at com.swmansion.rnscreens.ScreenViewManager.setActivityState(ScreenViewManager.kt:49)
    at com.swmansion.rnscreens.ScreenViewManager.setActivityState(ScreenViewManager.kt:34)
    at com.swmansion.rnscreens.ScreenViewManager.setActivityState(ScreenViewManager.kt:21)
    at com.facebook.react.viewmanagers.RNSScreenManagerDelegate.setProperty(RNSScreenManagerDelegate.java:81)
    at com.facebook.react.uimanager.ViewManagerPropertyUpdater.updateProps(ViewManagerPropertyUpdater.java:46)
    at com.facebook.react.uimanager.ViewManager.updateProperties(ViewManager.java:84)
    at com.facebook.react.views.view.ReactViewManagerWrapper$DefaultViewManager.updateProperties(ReactViewManagerWrapper.kt:59)
    at com.facebook.react.fabric.mounting.SurfaceMountingManager.updateProps(SurfaceMountingManager.java:872)
    at com.facebook.react.fabric.mounting.mountitems.IntBufferBatchMountItem.execute(IntBufferBatchMountItem.java:153)
    at com.facebook.react.fabric.mounting.MountItemDispatcher.executeOrEnqueue(MountItemDispatcher.java:351)
    at com.facebook.react.fabric.mounting.MountItemDispatcher.dispatchMountItems(MountItemDispatcher.java:274)
    at com.facebook.react.fabric.mounting.MountItemDispatcher.tryDispatchMountItems(MountItemDispatcher.java:120)
    at com.facebook.react.fabric.FabricUIManager$DispatchUIFrameCallback.doFrameGuarded(FabricUIManager.java:1245)
    at com.facebook.react.fabric.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:31)
    at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:175)
    at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:85)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1278)
    at android.view.Choreographer.doCallbacks(Choreographer.java:1019)
    at android.view.Choreographer.lambda$new$0$Choreographer(Choreographer.java:235)
    at android.view.-$$Lambda$Choreographer$zXV0PrqwmpdPajenUBozqc6c8Hs.run(Unknown Source:2)
    at android.os.Handler.handleCallback(Handler.java:900)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:219)
    at android.app.ActivityThread.main(ActivityThread.java:8668)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)

Steps to reproduce

  1. Run android react-native run-android
  2. Switch tabs multiple times

Snack or a link to a repository

https://github.com/Bort-777/react-native-screens-tabs-repro

Screens version

3.20.0

React Native version

0.71.6

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Fabric (New Architecture)

Build type

Debug mode

Device

Android emulator

Device model

No response

Acknowledgements

Yes

ken0x0a commented 1 year ago

As a temporary workaround (?),

set detachInactiveScreens={false} for StackNavigator https://reactnavigation.org/docs/stack-navigator/#detachinactivescreens to prevent this error.

JeanSilvany commented 1 year ago

Same issue!

franciscomaneiro commented 11 months ago

Is there any update for this issue? I have this exact problem

tcloudAce commented 6 months ago

detachInactiveScreens={false} is work

JeanSilvany commented 6 months ago

This crash occurs on enable Fabric.

Add this line in your Navigator and fix the problem.

detachInactiveScreens={false}

foyarash commented 4 months ago

I'm encountering the same issue aswell.

https://github.com/foyarash/rn-screens-android-crash-tabs

This happens when i have stack navigators inside tab navigator's screens. To get the error, i need to switch tabs exactly 5 times.

This does not happen when I don't use stack navigators as tab screens. And I can confirm that=

foyarash commented 4 months ago

I'm encountering the same issue aswell.

https://github.com/foyarash/rn-screens-android-crash-tabs

This happens when i have stack navigators inside tab navigator's screens. To get the error, i need to switch tabs exactly 5 times.

This does not happen when I don't use stack navigators as tab screens. And I can confirm that=

  • the issue does not occur on old arch
  • detachInactiveScreens={false} fixes the issue but is not optimal since we want to keep the optimization

Adding some detail to this, since I am trying to add some breakpoints into the lib to try finding the cause of the issue.

I noticed a slight difference of behavior in the ScreenContainer.kt onUpdate function.

I am doing the same thing in both old and new arch: switch from TabA to TabB, then TabB to TabA and so on. I added a breakpoint here

What I noticed is that, in the onUpdate function:

I don't know if that would be the cause of the issue, but I hope this is a first step to find it

cjones26 commented 2 months ago

@foyarash were you able to deduce anything further in regards to a root cause or better solution?

foyarash commented 2 months ago

@cjones26 sadly no, my latest comment on this issue is the most info I could provide. I hope a solution will be found.

foyarash commented 2 weeks ago

Any update on this ? With the new architecture becoming the default with 0.76, this is kind of a big blocker IMO