From 4f3b17412018a10f9293247c802598d2b94a844b Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Tue, 26 Jan 2021 10:48:56 -0800 Subject: [PATCH] Guard against setId being called on the ReactRootView outside of RN core Summary: The RootView being managed by Fabric should have an id of View.NO_ID when it is "handed over" to RN. This is true for Fabric and non-Fabric and setting a custom id on the ReactRootView has never been supported. I'm temporarily (?) adding an additional check earlier and into ReactRootView to hopefully catch any of these issues early. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D26077509 fbshipit-source-id: 59e1ec080504e50698acc654c29120f039238a96 --- .../main/java/com/facebook/react/ReactRootView.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index bbf8b5db68d9b9..2ee520cf05f7c6 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -646,6 +646,16 @@ private void attachToReactInstanceManager() { Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "attachToReactInstanceManager"); ReactMarker.logMarker(ReactMarkerConstants.ROOT_VIEW_ATTACH_TO_REACT_INSTANCE_MANAGER_START); + // React Native requires that the RootView id be managed entirely by React Native, and will + // crash in addRootView/startSurface if the native View id isn't set to NO_ID. + if (getId() != View.NO_ID) { + throw new IllegalViewOperationException( + "Trying to attach a ReactRootView with an explicit id already set to [" + + getId() + + "]. 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."); + } + try { if (mIsAttachedToInstance) { return;