-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Brownfield app crashes when using ReactFragment on new architecture #46566
Comments
Have the same issue when just trying to enable New Architecture on existing project. RN 0.75.3
|
Thanks for attaching a reproducer @gmantuanrosa There is a bug inside |
Thanks to look into it @cortinico! I had the same issue when using Activity as well (also mentioned by @Sky). Probably because they share the same ReactDelegate? Can you say that this will also fix Activity issues? If you want I can update the repro to have a React Activity being launched as well 😄 |
Yes please. I'd say we first need to fix the Activity scenario, and then get back to the Fragment one. If you could update the repo to use activities instead, it would be extremely helpful |
Fortunately I could make it work the Fabric React Activity but there is now an example in the reproducible, I still can't make Fragments work. Also I only got this activity issue once and I don't know how can I reproduce it again. |
Ok so sharing my findings so far (perhaps they'll help you @gmantuanrosa) but I need to get back to this next week.
react-native/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactFragment.java Lines 59 to 75 in 893a4b3
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String mainComponentName = null;
Bundle launchOptions = null;
Boolean fabricEnabled = null;
if (getArguments() != null) {
mainComponentName = getArguments().getString(ARG_COMPONENT_NAME);
launchOptions = getArguments().getBundle(ARG_LAUNCH_OPTIONS);
fabricEnabled = getArguments().getBoolean(ARG_FABRIC_ENABLED);
}
if (mainComponentName == null) {
throw new IllegalStateException("Cannot loadApp if component name is null");
}
if (!ReactFeatureFlags.enableBridgelessArchitecture) {
mReactDelegate =
new ReactDelegate(
getActivity(), getReactNativeHost(), mainComponentName, launchOptions, fabricEnabled);
} else {
mReactDelegate =
new ReactDelegate(
getActivity(), getReactHost(), mainComponentName, launchOptions);
}
}
private ReactHost getReactHost() {
return ((ReactApplication) getActivity().getApplication()).getReactHost();
} You will then observe that the app crashes with a different crash:
Full stacktrace:
I haven't been able to isolate why is it crashing with this error. It can either be because of the Any investigation is more than appreciated @gmantuanrosa |
Summary: I've just noticed that ReactFragment is not properly instantiating the `ReactDelegate` with a ReactHost when on Bridgeless. This causes Fragments to crash when the app is on bridgeless mode. Fixes facebook#46566 Changelog: [Android] [Fixed] - ReactFragment should properly instantiate ReactDelegate on Bridgeless Differential Revision: D63319977
…facebook#46623) Summary: Pull Request resolved: facebook#46623 I've just noticed that ReactFragment is not properly instantiating the `ReactDelegate` with a ReactHost when on Bridgeless. This causes Fragments to crash when the app is on bridgeless mode. Fixes facebook#46566 Changelog: [Android] [Fixed] - ReactFragment should properly instantiate ReactDelegate on Bridgeless Reviewed By: mdvacca Differential Revision: D63319977
Summary: I've just noticed that ReactFragment is not properly instantiating the `ReactDelegate` with a ReactHost when on Bridgeless. This causes Fragments to crash when the app is on bridgeless mode. Fixes facebook#46566 Changelog: [Android] [Fixed] - ReactFragment should properly instantiate ReactDelegate on Bridgeless Differential Revision: D63319977
…tentView` Summary: Fixes facebook#46566 Currently `ReactFragment` and `ReactDelegate` don't work in OSS + New Architecture because we call `Activity.setContentView` on the host activity. That result on us replacing the whole activity layout, even when the user wants to use a Fragment. As we do have `ReactActivityDelegate` that already does this: https://github.com/facebook/react-native/blob/94b77938435693792e57c96d76691d58d7361530/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java#L138 So this call is unncessary. I've also updated the relative documentation here: facebook/react-native-website#4232 Changelog: [Android] [Fixed] - fix: ReactDelegate/ReactFragment crashing on New Architecture apps Differential Revision: D63464367
I've spent more time on this and finally fixed it.
I've opened a Pick request for those fixes to be included inside 0.76 here: |
Summary: I've just noticed that ReactFragment is not properly instantiating the `ReactDelegate` with a ReactHost when on Bridgeless. This causes Fragments to crash when the app is on bridgeless mode. Fixes facebook#46566 Changelog: [Android] [Fixed] - ReactFragment should properly instantiate ReactDelegate on Bridgeless Differential Revision: D63319977
…tentView` (facebook#46671) Summary: Pull Request resolved: facebook#46671 Fixes facebook#46566 Currently `ReactFragment` and `ReactDelegate` don't work in OSS + New Architecture because we call `Activity.setContentView` on the host activity. That result on us replacing the whole activity layout, even when the user wants to use a Fragment. As we do have `ReactActivityDelegate` that already does this: https://github.com/facebook/react-native/blob/94b77938435693792e57c96d76691d58d7361530/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java#L138 So this call is unncessary. I've also updated the relative documentation here: facebook/react-native-website#4232 Changelog: [Android] [Fixed] - fix: ReactDelegate/ReactFragment crashing on New Architecture apps Reviewed By: rozele Differential Revision: D63464367
…facebook#46623) Summary: Pull Request resolved: facebook#46623 I've just noticed that ReactFragment is not properly instantiating the `ReactDelegate` with a ReactHost when on Bridgeless. This causes Fragments to crash when the app is on bridgeless mode. Fixes facebook#46566 Changelog: [Android] [Fixed] - ReactFragment should properly instantiate ReactDelegate on Bridgeless Reviewed By: mdvacca Differential Revision: D63319977
…tentView` (#46671) Summary: Pull Request resolved: #46671 Fixes #46566 Currently `ReactFragment` and `ReactDelegate` don't work in OSS + New Architecture because we call `Activity.setContentView` on the host activity. That result on us replacing the whole activity layout, even when the user wants to use a Fragment. As we do have `ReactActivityDelegate` that already does this: https://github.com/facebook/react-native/blob/94b77938435693792e57c96d76691d58d7361530/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java#L138 So this call is unncessary. I've also updated the relative documentation here: facebook/react-native-website#4232 Changelog: [Android] [Fixed] - fix: ReactDelegate/ReactFragment crashing on New Architecture apps Reviewed By: rozele Differential Revision: D63464367 fbshipit-source-id: acbfbf7d68eb79657b811a5a9a0d3f72660ec94a
Description
I have an Android app that is using React Native for some activities and I decided to follow React Native documentation to add into Fragments as well. My App has a mix of XML and Compose navigation and Fragments for the Bottom Tab Navigation -- one of the tab being React Native.
It does work fine until I enable the new architecture, generating app crashes once the Fragment is mounted. I also had the same issue creating a custom Activity with the same crash behavior.
Steps to reproduce
React Native Version
0.75.3
Affected Platforms
Runtime - Android
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/gmantuanrosa/brownfield-rn-fragment
Screenshots and Videos
No response
The text was updated successfully, but these errors were encountered: