diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index 02fcd63fade..4c863b70209 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -431,8 +431,9 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { @SuppressWarnings("unused") @AnyThread @ThreadConfined(ANY) - private MountItem createBatchMountItem(MountItem[] items, int size, int commitNumber) { - return new BatchMountItem(items, size, commitNumber); + private MountItem createBatchMountItem( + int rootTag, MountItem[] items, int size, int commitNumber) { + return new BatchMountItem(rootTag, items, size, commitNumber); } @DoNotStrip @@ -786,6 +787,22 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { } } + // Make sure surface associated with this MountItem has been started, and not stopped. + // TODO T68118357: clean up this logic and simplify this method overall + if (mountItem instanceof BatchMountItem) { + BatchMountItem batchMountItem = (BatchMountItem) mountItem; + int rootTag = batchMountItem.getRootTag(); + if (mReactContextForRootTag.get(rootTag) == null) { + ReactSoftException.logSoftException( + TAG, + new ReactNoCrashSoftException( + "dispatchMountItems: skipping batched item: surface not available [" + + rootTag + + "]")); + continue; + } + } + // TODO: if early ViewCommand dispatch ships 100% as a feature, this can be removed. // This try/catch catches Retryable errors that can only be thrown by ViewCommands, which // won't be executed here in Early Dispatch mode. diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp index f78973739fc..63f9c78265d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp @@ -841,11 +841,15 @@ void Binding::schedulerDidFinishTransaction( static auto createMountItemsBatchContainer = jni::findClassStatic(UIManagerJavaDescriptor) ->getMethod( - jtypeArray, jint, jint)>( + jint, jtypeArray, jint, jint)>( "createBatchMountItem"); auto batch = createMountItemsBatchContainer( - localJavaUIManager, mountItemsArray.get(), position, commitNumber); + localJavaUIManager, + surfaceId, + mountItemsArray.get(), + position, + commitNumber); static auto scheduleMountItem = jni::findClassStatic(UIManagerJavaDescriptor) ->getMethod