Skip to content

Commit

Permalink
Mark root view as attached after executing all pending operations (fa…
Browse files Browse the repository at this point in the history
…cebook#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`.

Reviewed By: sammy-SC

Differential Revision: D57968937
  • Loading branch information
rubennorte authored and facebook-github-bot committed May 30, 2024
1 parent d08ba0f commit fb870c5
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,20 @@ private void addRootView(@NonNull final View rootView) {
if (rootView instanceof ReactRoot) {
((ReactRoot) rootView).setRootViewTag(mSurfaceId);
}
mRootViewAttached = true;

if (!ReactNativeFeatureFlags.forceBatchingMountItemsOnAndroid()) {
mRootViewAttached = true;
}

executeMountItemsOnViewAttach();

if (ReactNativeFeatureFlags.forceBatchingMountItemsOnAndroid()) {
// By doing this after `executeMountItemsOnViewAttach`, we ensure
// that any operations scheduled while processing this queue are
// also added to the queue, instead of being processed immediately
// through the queue in `MountItemDispatcher`.
mRootViewAttached = true;
}
};

if (UiThreadUtil.isOnUiThread()) {
Expand Down

0 comments on commit fb870c5

Please sign in to comment.