software-mansion / software-mansion/react-native-screens
[Android] ViewGroup.dispatchAttachedToWindow crash with Fabric architecture
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3.7k
- Forks
- 714
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 71
Description
Description
Experiencing NullPointerException crashes in ViewGroup.dispatchAttachedToWindow when using React Native Screens with the new architecture (Fabric) enabled.
Stack Trace
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getVisibility()' on a null object reference
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3526)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3525)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3525)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3525)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3525)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3525)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3525)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3525)
at android.view.ViewGroup.addViewInner(ViewGroup.java:5330)
at android.view.ViewGroup.addView(ViewGroup.java:5116)
at android.view.ViewGroup.addView(ViewGroup.java:5056)
at androidx.fragment.app.FragmentStateManager.addViewToContainer(FragmentStateManager.java:881)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:565)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:272)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1943)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1845)
at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1751)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:323)
at com.swmansion.rnscreens.ScreenStack.onUpdate(ScreenStack.kt:262)
at com.swmansion.rnscreens.ScreenContainer.performUpdates(ScreenContainer.kt:359)
at com.swmansion.rnscreens.ScreenContainer.onScreenChanged$lambda$7(ScreenContainer.kt:342)
at android.os.Handler.handleCallback(Handler.java:991)
at android.os.Handler.dispatchMessage(Handler.java:102)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.kt:20)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8934)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
Environment
- React Native version: 0.79.3
- React Native Screens version: 4.11.1
- Platform: Android
- Architecture: Fabric (New Architecture) enabled
- Device: Multiple Android devices (not device-specific)
Steps to Reproduce
- Enable Fabric architecture in your React Native app
- Use React Native Screens for navigation
- Perform rapid navigation between screens
- The crash occurs randomly during fragment transactions
Expected Behavior
Navigation should work smoothly without crashes.
Actual Behavior
App crashes with NullPointerException in ViewGroup.dispatchAttachedToWindow.
Additional Context
- This started happening after enabling the new architecture (Fabric)
- The crash is intermittent and seems to be related to race conditions
- Occurs during fragment transactions when views are being attached/detached
- Not reproducible consistently, but happens frequently enough to be a critical issue
Possible Root Cause
The issue appears to be a race condition between:
- React Native's Fabric architecture view management
- Android's fragment transaction system
- React Native Screens' fragment-based navigation
When Fabric nullifies views during its async operations, the fragment transaction tries to access those views, causing the NullPointerException.
Steps to reproduce
- Enable Fabric architecture in your React Native app
- Use React Native Screens for navigation
- Perform rapid navigation between screens
- The crash occurs randomly during fragment transactions
Snack or a link to a repository
cannot share
Screens version
4.11.1
React Native version
0.79.3
Platforms
Android
JavaScript runtime
Hermes
Workflow
React Native (without Expo)
Architecture
Fabric (New Architecture)
Build type
Release mode
Device
Real device
Device model
No response
Acknowledgements
Yes
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the crash path through Android's ViewGroup.dispatchAttachedToWindow and the React Native Screens entries at ScreenStack.kt:262 and ScreenContainer.kt:359/342. Reproduce rapid navigation with Fabric enabled on Android and inspect the fragment transaction flow. Done means the intermittent NullPointerException no longer occurs during repeated navigation, with regression coverage if the project exposes a suitable test path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, react-native
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100