Skip to content

Commit 546821e

Browse files
rubennortefacebook-github-bot
authored andcommitted
Mark root view as attached after executing all pending operations (facebook#44726)
Summary: Changelog: [internal] ## Context We ran an experiment to test synchronous state updates in Fabric and we saw some crashes on Android. Those crashes were caused by mounting operations not being applied in the correct order. There were 2 root causes for that problem: 1. State updates triggered during mount would be committed and mounted synchronously during that specific mount operation. That caused problems like trying to clip views that weren't created already (as we were processing the state update for the content offset before we actually created the child views). 2. Same problem as before, but with mount operations that were processed when the root view wasn't available yet (this is a separate queue). We tried to fix the problem in facebook#44015, but the solution for 2) was incorrect, as we didn't account for those operations being in a different queue (it was reverted in facebook#44724). ## Changes I think the right solution for point 2) is that, instead of marking the root view as available and then process all pending operations, we flip those operations. That was, if there are any mount operations as a side-effect of processing that queue, those will also be added to the same queue, instead of being processed immediately in `MountItemDispatcher`. Differential Revision: D57968937
1 parent e36eb35 commit 546821e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,20 @@ private void addRootView(@NonNull final View rootView) {
222222
if (rootView instanceof ReactRoot) {
223223
((ReactRoot) rootView).setRootViewTag(mSurfaceId);
224224
}
225-
mRootViewAttached = true;
225+
226+
if (!ReactNativeFeatureFlags.forceBatchingMountItemsOnAndroid()) {
227+
mRootViewAttached = true;
228+
}
226229

227230
executeMountItemsOnViewAttach();
231+
232+
if (ReactNativeFeatureFlags.forceBatchingMountItemsOnAndroid()) {
233+
// By doing this after `executeMountItemsOnViewAttach`, we ensure
234+
// that any operations scheduled while processing this queue are
235+
// also added to the queue, instead of being processed immediately
236+
// through the queue in `MountItemDispatcher`.
237+
mRootViewAttached = true;
238+
}
228239
};
229240

230241
if (UiThreadUtil.isOnUiThread()) {

0 commit comments

Comments
 (0)