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

3.0.0-rc.2 Android - TypeError: Cannot read property 'stateNode' of undefined #3534

Closed
kyle-ssg opened this issue Sep 1, 2022 · 26 comments
Closed
Labels
Platform: Android This issue is specific to Android 🏰 Reanimated 3 Repro provided A reproduction with a snippet of code, snack or repo is provided Reproducible 🎉

Comments

@kyle-ssg
Copy link

kyle-ssg commented Sep 1, 2022

Description

I'm attempting to use Fabric with 3.0.0-rc.2. iOS works fine however on Android I get the following attempting to render an Animated.View.

 ERROR  TypeError: Cannot read property 'stateNode' of undefined

This error is located at:
    in AnimatedComponent(View) (at createAnimatedComponent.tsx:533)

Steps to reproduce

Render an <Animated.View/>

Snack or a link to a repository

https://github.com/kyle-ssg/reanimated-reproduction

Reanimated version

3.0.0-rc.2

React Native version

0.69.5 (I can confirm this also happens on RN 0.70.rc-4)

Platforms

Android

JavaScript runtime

JSC

Workflow

React Native (without Expo)

Architecture

Fabric (New Architecture)

Build type

Debug mode

Device

Android emulator

Device model

No response

Acknowledgements

Yes

@kyle-ssg kyle-ssg added the Needs review Issue is ready to be reviewed by a maintainer label Sep 1, 2022
@github-actions github-actions bot added Platform: Android This issue is specific to Android Repro provided A reproduction with a snippet of code, snack or repo is provided labels Sep 1, 2022
@Chenbao2021
Copy link

Same problem

@khushal87
Copy link

khushal87 commented Sep 21, 2022

Facing the same problem with 0.70.1 while opting in the new arch with 3.0.0-rc.2.

@khushal87
Copy link

khushal87 commented Sep 21, 2022

Hey @kyle-ssg, any chance you are using @gorhom's bottom-sheet, too?

Error trace:

This error is located at:
in FlatList (created by AnimatedComponent(FlatList))
in AnimatedComponent(FlatList)
in Unknown (created by NativeViewGestureHandler)
in NativeViewGestureHandler (created by BottomSheetFlatList)
in RCTView (created by View)
in View (created by AnimatedComponent(View))
in AnimatedComponent(View)
in Unknown (created by PanGestureHandler)
in PanGestureHandler (created by BottomSheetDraggableViewComponent)
in BottomSheetDraggableViewComponent (created by BottomSheetFlatList)
in BottomSheetFlatList (created by BottomSheetFlatList)
in RCTView (created by View)
in View (created by AnimatedComponent(View))
in AnimatedComponent(View)
in Unknown (created by PanGestureHandler)
in PanGestureHandler (created by BottomSheetDraggableViewComponent)
in BottomSheetDraggableViewComponent (created by BottomSheet)
in RCTView (created by View)
in View (created by AnimatedComponent(View))
in AnimatedComponent(View)
in Unknown (created by BottomSheet)
in RCTView (created by View)
in View (created by AnimatedComponent(View))
in AnimatedComponent(View)
in Unknown (created by BottomSheet)
in RCTView (created by View)
in View (created by BottomSheetContainerComponent)
in BottomSheetContainerComponent (created by BottomSheet)
in BottomSheetGestureHandlersProvider (created by BottomSheet)
in BottomSheet (created by BottomSheet)
in AttachmentPicker (created by OverlayProvider)
in ThemeProvider (created by OverlayProvider)
in ImageGalleryProvider (created by OverlayProvider)
in AttachmentPickerProvider (created by OverlayProvider)
in MessageOverlayProvider (created by OverlayProvider)
in TranslationProvider (created by OverlayProvider)
in OverlayProvider (created by App)
in RCTView (created by View)
in View (created by GestureHandlerRootView)
in GestureHandlerRootView (created by App)
in EnsureSingleNavigator
in BaseNavigationContainer
in ThemeProvider
in NavigationContainerInner (created by App)
in App
in RNCSafeAreaProvider (created by SafeAreaProvider)
in SafeAreaProvider
in Unknown
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in NewArchStream(RootComponent), js engine: hermes

@kyle-ssg
Copy link
Author

kyle-ssg commented Sep 21, 2022

Hmm, I was but I could replicate this by rendering a plain reanimated view in an empty app too. See https://github.com/kyle-ssg/reanimated-reproduction/blob/main/mobile/app/App.tsx#L5

@keshav-raj
Copy link

Facing the same issue on new Archtecture

@keshav-raj
Copy link

keshav-raj commented Sep 26, 2022

@kyle-ssg Did you find any workaround am also facing the same issue. If I have <Animated. View /> it's failing

@anirudhdream11
Copy link

anirudhdream11 commented Sep 29, 2022

Any solution till now?
I am facing same issue for Android only with new architecture on RN 0.70.1, However ios looks fine.

@thanggggg1
Copy link

Any solution till now?
I am facing same issue for Android only with new architecture on RN 0.70.1, However ios looks fine.

Did you find the solution

@ugurdalkiran
Copy link

The same problem continues.

@kyle-ssg
Copy link
Author

Yeah just to confirm, haven't found a workaround for this.

@anirudhdream11
Copy link

Any solution till now?
I am facing same issue for Android only with new architecture on RN 0.70.1, However ios looks fine.

Did you find the solution

It was worked for me when I upgraded reanimated to "3.0.0-rc.3"

Combination of below dependencies was worked for me :
"react-native": "0.70.1",
"react-native-gradle-plugin": "0.70.1",
"react-native-reanimated": "3.0.0-rc.3",
"react-native-safe-area-context": "4.4.1",
"react-native-screens": "3.17.0",

@tomekzaw
Copy link
Member

Hey @kyle-ssg, thanks for submitting this issue and marking other issues as duplicate.

Based on the repro you have provided, I was able to successfully reproduce the issue on app launch.

We will investigate this error further.

@tomekzaw tomekzaw added Reproducible 🎉 and removed Needs review Issue is ready to be reviewed by a maintainer labels Nov 16, 2022
@tomekzaw
Copy link
Member

tomekzaw commented Nov 16, 2022

The root cause of the issue is the fact that Reanimated uses Fabric mode while the app still runs on Paper (old renderer):

As you can see, there's no "fabric":true in the logs, meaning that your app still runs on the old architecture.

Based on the value of newArchEnabled property, Reanimated correctly detects that Fabric is enabled and sets global._IS_FABRIC to true which causes Reanimated to use Fabric implementation (e.g. to obtain ShadowNodeWrapper from stateNode field, which is undefined on Paper).

The problem is that for some reason React Native doesn't enable Fabric. This may be because your app is totally out-of-sync with React Native 0.69.5 template. In particular, the Android app still runs on Paper because the following method is missing:

    @Override
    protected ReactRootView createRootView() {
      ReactRootView reactRootView = new ReactRootView(getContext());
      // If you opted-in for the New Architecture, we enable the Fabric Renderer.
      reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
      return reactRootView;
    }

Additionally, many of the third-party libraries that you use are not Fabric-compatible yet, for instance:

  • react-native-linear-gradient
  • react-native-modal-datetime-picker
  • react-native-keyboard-aware-scroll-view
  • react-native-webview

I've replaced MainActivity.java in your project with the one from RN 0.69.5 app template (see here), changed the Java package and app name. I also removed all other third-party libraries from package.json and other Android-specific files. The app now runs on Fabric and the issue is gone:

Closing this issue as it's not a bug in Reanimated, but a config issue on your side.

@ugurdalkiran
Copy link

With Fabric enabled, the signed APK app crashes on first launch. That's why I disable Fabric.

@fgagneten
Copy link

@khushal87 facing the same issue when playing around with @gorhom's bottom-sheet

@tomekzaw
Copy link
Member

@ugurdalkiran @fgagneten

  1. Do you have Fabric (new architecture) enabled?
  2. If yes, do you have {"fabric":true} in Metro bundler console?
  3. Can you replicate the issue on a fresh React Native app initialized with npx react-native init MyApp --version 0.x.y?

@kyle-ssg
Copy link
Author

@tomekzaw Thanks so much for the explaination and the "fabric":true tip!

@fgagneten
Copy link

@tomekzaw

  1. yes, I do (android)
  2. Yes, I do: Running "myapp" with {"fabric":true,"initialProps":{"concurrentRoot":true},"rootTag":1}
  3. I couldn't replicate it due to the number of dependencies I have right now. I will try again tonight

@kyle-ssg
Copy link
Author

kyle-ssg commented Nov 20, 2022

Since yesterday I got my setup working (iOS and android) with quite a few dependencies, including @gorhom's bottom sheet, though from this I learnt I won't switch to the new architecture for a while, seems too risky and some really important modules aren't ready.

A few things:

  • If you're coming from a project that has gone through many version upgrades, https://github.com/software-mansion/react-native-reanimated/tree/main/FabricExample is an excellent example to look at to compare with your own, in particular the AppDelegate.mm and build.gradle's / MainApplication / MainActivity
  • There are lots of red herring errors due to cache when opting in and out, removing iOS/Android build folders and clearing all the caches will save you from troubleshooting.

Here's a list of dependencies that currently work for me

     react: 18.1.0 => 18.1.0 
    react-native: 0.70.6 => 0.70.6 

        "@gorhom/bottom-sheet": "4.4.5",
 "react-native-mmkv-storage": "^0.7.6",
        "react-native-gesture-handler": "2.8.0",
        "react-native-reanimated": "3.0.0-rc.3",
         "react-native-safe-area-context": "^4.4.1",
         "react-native-svg": "^13.3.0",
         "react-native-date-picker": "^4.2.6",

A quick note on the above. In order to work, @react-native-community/datetimepicker requires this in react-native-config.js

    '@react-native-community/datetimepicker': {
      platforms: {
        android: {
          androidMkPath: null,
          cmakeListsPath: null,
          componentDescriptors: null,
          libraryName: null,
        },
      },
    },

These don't work

@khushal87
Copy link

Hey @kyle-ssg do you recommend not upgrading to new arch with the bottom-sheet version 4.4.5?

@prince-sugarfit
Copy link

Is there any way I can use it with newArchitecture = true & fabric = false?

@tomekzaw
Copy link
Member

tomekzaw commented Jul 25, 2023

@prince-sugarfit nope, we don't support this currently (and honestly we don't plan to).
edit: I'm assuming you mean turboModules = true & fabric = false

@fgagneten
Copy link

Is there any workaround to fix this issue? (I always get this issue using Gorhom + BottomSheetVirtuslizedList).

Only crash with Fabric = true

@LadislavBohm
Copy link

If someone is running into similar issue (for me it was property 'version' of undefined) my solution was to modify properly metro.config.js. I had react-native-svg-transformer included in project as well and you need to follow the new way to integrate it on it's official github page.

@hssdiv
Copy link

hssdiv commented Feb 2, 2024

If someone is running into similar issue (for me it was property 'version' of undefined) my solution was to modify properly metro.config.js. I had react-native-svg-transformer included in project as well and you need to follow the new way to integrate it on it's official github page.

Thanks for the tip, had that in expo-app and I simply needed to set sourceExts the way official documentation says it should be set (same way as assetExts)
https://docs.expo.dev/guides/customizing-metro/

@TassainRasool
Copy link

react native version == 0.68.5
on updating the reanimated from 2.17.0 (RNReanimated (2.17.0)) to any higher version I am facing many issues with it.
some common issues are showing undefined methods which are working fine with the 1.17.0 version.

logs

any suggestions or sol?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android This issue is specific to Android 🏰 Reanimated 3 Repro provided A reproduction with a snippet of code, snack or repo is provided Reproducible 🎉
Projects
None yet
Development

No branches or pull requests