Skip to content

Commit 3429dc1

Browse files
psionic12facebook-github-bot
authored andcommitted
Log a SoftException on SurfaceMountingManager.addRootView (facebook#34785)
Summary: Follow the same solution (do not throw a crash when view ID is set already) used in `ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java` for `ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java` ## Changelog [Android] [Changed] - Log a SoftException on SurfaceMountingManager.addRootView Pull Request resolved: facebook#34785 Test Plan: None Reviewed By: cipolleschi Differential Revision: D40022263 Pulled By: cortinico fbshipit-source-id: d565d2831e2833ccea55f28ea16083b7bae0ed32
1 parent 3dcf86b commit 3429dc1

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,22 @@ private void addRootView(@NonNull final View rootView) {
211211
+ " tag: [%d]",
212212
rootView.getId(),
213213
mSurfaceId);
214-
throw new IllegalViewOperationException(
215-
"Trying to add a root view with an explicit id already set. React Native uses the"
216-
+ " id field to track react tags and will overwrite this field. If that is"
217-
+ " fine, explicitly overwrite the id field to View.NO_ID before calling"
218-
+ " addRootView.");
214+
// This behavior can not be guaranteed in hybrid apps that have a native android layer
215+
// over
216+
// which reactRootViews are added and the native views need to have ids on them in order
217+
// to
218+
// work.
219+
// Hence this can cause unnecessary crashes at runtime for hybrid apps.
220+
// So converting this to a soft exception such that pure react-native devs can still see
221+
// the
222+
// warning while hybrid apps continue to run without crashes
223+
ReactSoftExceptionLogger.logSoftException(
224+
TAG,
225+
new IllegalViewOperationException(
226+
"Trying to add a root view with an explicit id already set. React Native uses"
227+
+ " the id field to track react tags and will overwrite this field. If that"
228+
+ " is fine, explicitly overwrite the id field to View.NO_ID before calling"
229+
+ " addRootView."));
219230
}
220231
rootView.setId(mSurfaceId);
221232

0 commit comments

Comments
 (0)