Skip to content

Commit

Permalink
Log a SoftException on SurfaceMountingManager.addRootView (#34785)
Browse files Browse the repository at this point in the history
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: #34785

Test Plan: None

Reviewed By: cipolleschi

Differential Revision: D40022263

Pulled By: cortinico

fbshipit-source-id: d565d2831e2833ccea55f28ea16083b7bae0ed32
  • Loading branch information
psionic12 authored and facebook-github-bot committed Jun 20, 2024
1 parent 3dcf86b commit 3429dc1
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,22 @@ private void addRootView(@NonNull final View rootView) {
+ " 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);

Expand Down

0 comments on commit 3429dc1

Please sign in to comment.