Skip to content

Commit

Permalink
Implement potential fix for mounting errors during synchronous state …
Browse files Browse the repository at this point in the history
…updates (v2) (facebook#44492)

Summary:

Changelog: [internal]

This is a new attempt at fixing mounting errors during synchronous state updates after what we tried in facebook#44015.

That fix didn't work because `dispatchMountItems` actually makes a copy of the mount items that it's going to process, so when we added the mount items to the list they were actually not being picked up by the current processing.

This changes the fix to expose a new list of mount items being processed, and if that's defined then we add it to the list. Otherwise we process as usual.

Reviewed By: sammy-SC

Differential Revision: D57107212
  • Loading branch information
rubennorte authored and facebook-github-bot committed May 8, 2024
1 parent 4290ef5 commit 81cf125
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,7 @@ public void executeItems(Queue<MountItem> items) {
// This executor can be technically accessed before the dispatcher is created,
// but if that happens, something is terribly wrong
if (ReactNativeFeatureFlags.forceBatchingMountItemsOnAndroid()) {
for (MountItem mountItem : items) {
mMountItemDispatcher.addMountItem(mountItem);
}
mMountItemDispatcher.tryDispatchMountItems();
mMountItemDispatcher.batchMountItemsIfNecessary(items);
} else {
mMountItemDispatcher.dispatchMountItems(items);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class MountItemDispatcher {
@NonNull
private final ConcurrentLinkedQueue<MountItem> mMountItems = new ConcurrentLinkedQueue<>();

@Nullable private List<MountItem> mCurrentMountItemsBatch;

@NonNull
private final ConcurrentLinkedQueue<MountItem> mPreMountItems = new ConcurrentLinkedQueue<>();

Expand All @@ -69,6 +71,16 @@ public void addMountItem(MountItem mountItem) {
mMountItems.add(mountItem);
}

@UiThread
@ThreadConfined(UI)
public void batchMountItemsIfNecessary(Queue<MountItem> items) {
if (mCurrentMountItemsBatch != null) {
mCurrentMountItemsBatch.addAll(items);
} else {
dispatchMountItems(items);
}
}

public void addPreAllocateMountItem(MountItem mountItem) {
// We do this check only for PreAllocateViewMountItem - and not DispatchMountItem or regular
// MountItem - because PreAllocateViewMountItems are not batched, and is relatively more
Expand Down Expand Up @@ -103,10 +115,6 @@ public void tryDispatchMountItems() {
return;
}

if (ReactNativeFeatureFlags.forceBatchingMountItemsOnAndroid()) {
mInDispatch = true;
}

final boolean didDispatchItems;
try {
didDispatchItems = dispatchMountItems();
Expand Down Expand Up @@ -189,6 +197,10 @@ private boolean dispatchMountItems() {
getAndResetViewCommandMountItems();
List<MountItem> mountItemsToDispatch = getAndResetMountItems();

if (ReactNativeFeatureFlags.forceBatchingMountItemsOnAndroid()) {
mCurrentMountItemsBatch = mountItemsToDispatch;
}

if (mountItemsToDispatch == null && viewCommandMountItemsToDispatch == null) {
return false;
}
Expand Down Expand Up @@ -305,6 +317,8 @@ private boolean dispatchMountItems() {

mItemDispatchListener.didMountItems(mountItemsToDispatch);

mCurrentMountItemsBatch = null;

Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);

return true;
Expand Down

0 comments on commit 81cf125

Please sign in to comment.