diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java index 63b79a4d222..754bc894574 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java @@ -211,11 +211,22 @@ public class SurfaceMountingManager { + " tag: [%d]", rootView.getId(), mSurfaceId); - throw new IllegalViewOperationException( - "Trying to add a root view with an explicit id already set. React Native uses the" - + " id field to track react tags and will overwrite this field. If that is" - + " fine, explicitly overwrite the id field to View.NO_ID before calling" - + " addRootView."); + // This behavior can not be guaranteed in hybrid apps that have a native android layer + // over + // which reactRootViews are added and the native views need to have ids on them in order + // to + // work. + // Hence this can cause unnecessary crashes at runtime for hybrid apps. + // So converting this to a soft exception such that pure react-native devs can still see + // the + // warning while hybrid apps continue to run without crashes + ReactSoftExceptionLogger.logSoftException( + TAG, + new IllegalViewOperationException( + "Trying to add a root view with an explicit id already set. React Native uses" + + " the id field to track react tags and will overwrite this field. If that" + + " is fine, explicitly overwrite the id field to View.NO_ID before calling" + + " addRootView.")); } rootView.setId(mSurfaceId);