question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Could not find root view for a given ancestor with tag

See original GitHub issue

Description

We are seeing the following crash on Android:

com.facebook.react.bridge.JSApplicationIllegalArgumentException: Could find root view for a given ancestor with tag 3199
    at com.swmansion.gesturehandler.react.RNGestureHandlerModule.tryInitializeHandlerForReactRootView(RNGestureHandlerModule.java:18)
    at com.swmansion.gesturehandler.react.RNGestureHandlerModule.attachGestureHandler(RNGestureHandlerModule.java:1)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:18)
    at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:2)
    at com.facebook.react.bridge.queue.NativeRunnable.run(NativeRunnable.java)
    at android.os.Handler.handleCallback(Handler.java:869)
    at android.os.Handler.dispatchMessage(Handler.java:101)
    at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:1)
    at android.os.Looper.loop(Looper.java:206)
    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:8)
    at java.lang.Thread.run(Thread.java:764)

Screenshots

Screenshot 2021-10-04 at 17 09 33

Steps To Reproduce

I was not able to reproduce it consistently, but it seems to happen after the app goes to foreground.

Package versions

  • React: 17.0.1
  • React Native: >= 0.64.2
  • React Native Gesture Handler: 1.10.3
  • React Navigation: 5.14.4

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:20
  • Comments:48

github_iconTop GitHub Comments

12reactions
rdeiftcommented, Nov 2, 2021

+1

6reactions
jbaudanzacommented, Dec 20, 2021

I was able to resolve this issue in my project. The problem is that Codepush.restartApp doesn’t actually restart the app. Instead, it uses the ReactNativeInstanceManager class to reload the bundle:

https://github.com/facebook/react-native/blob/4fb49cd555942caba1515b6a03f8ccea931dfc90/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java#L435

This means that if any RN-GestureHandler components begin initializing before a Codepush.restartApp, there is a very good chance that when they finish., the RootNode doesn’t exist anymore. This is what causes the crash.

To solve this, you have to make sure there are no instances of RN-GestureHandler in the process of loading before a Codepush.restartApp operation. This includes things like react-navigation, which will mount gesture handlers behind the scenes.

In our case, when our app loads we begin a codepush sync. While the codepush is in any of these states, we render a simple View with no gesture handlers or react-navigation are mounted: CHECKING_FOR_UPDATE, DOWNLOADING_PACKAGE, UPDATE_INSTALLED, INSTALLING_UPDATE.

Only after the codepush is completely finished, it’s safe to mount any react-navigation components.

Read more comments on GitHub >

github_iconTop Results From Across the Web

In React Native, I am getting this error "Could not find root view ...
Could not find root view for a given ancestor with tag number. Attaching error message with piece of code which causing this error....
Read more >
Could not find root view for a given ancestor with tag
Description. We are seeing the following crash on Android: com.facebook.react.bridge.JSApplicationIllegalArgumentException: Could find root ...
Read more >
RootTag - React Native
RootTag is an opaque identifier assigned to the native root view of your React Native surface — i.e. the ReactRootView or RCTRootView instance ......
Read more >
Getting Started | React Native Gesture Handler
On Android RNGH does not work by default because modals are not located under React Native Root view in native hierarchy. To fix...
Read more >
View - Android Developers
You should not call methods that perform these actions on views yourself unless ... Tags may be specified with character sequence values in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found