Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ CommitStatus ShadowTree::tryCommit(

auto newRevisionNumber = currentRevision_.number + 1;

if (!isReactBranch) {
{
std::scoped_lock dispatchLock(EventEmitter::DispatchMutex());
updateMountedFlag(
currentRevision_.rootShadowNode->getChildren(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ void updateMountedFlag(
return;
}

// Mounted flags shouldn't be updated during the React revision merge
// because they were already set during the React branch commit. Setting them
// again would double-increment the EventEmitter's additive enable counter.
bool shouldUpdateMountedFlag =
commitSource != ShadowTreeCommitSource::ReactRevisionMerge;

// Runtime shadow node references are updated during the React revision
// commits so that JS can access layout data from the merged tree.
bool shouldUpdateRuntimeReference =
(commitSource == ShadowTreeCommitSource::React &&
ReactNativeFeatureFlags::updateRuntimeShadowNodeReferencesOnCommit()) ||
(ReactNativeFeatureFlags::
updateRuntimeShadowNodeReferencesOnCommitThread() &&
ShadowNode::getUseRuntimeShadowNodeReferenceUpdateOnThread());

if (!shouldUpdateMountedFlag && !shouldUpdateRuntimeReference) {
return;
}

size_t index = 0;

// Stage 1: Mount and unmount "updated" children.
Expand All @@ -47,15 +66,12 @@ void updateMountedFlag(
break;
}

newChild->setMounted(true);
oldChild->setMounted(false);
if (shouldUpdateMountedFlag) {
newChild->setMounted(true);
oldChild->setMounted(false);
}

if ((commitSource == ShadowTreeCommitSource::React &&
ReactNativeFeatureFlags::
updateRuntimeShadowNodeReferencesOnCommit()) ||
(ReactNativeFeatureFlags::
updateRuntimeShadowNodeReferencesOnCommitThread() &&
ShadowNode::getUseRuntimeShadowNodeReferenceUpdateOnThread())) {
if (shouldUpdateRuntimeReference) {
newChild->updateRuntimeShadowNodeReference(newChild);
}

Expand All @@ -68,25 +84,27 @@ void updateMountedFlag(
// State 2: Mount new children.
for (index = lastIndexAfterFirstStage; index < newChildren.size(); index++) {
const auto& newChild = newChildren[index];
newChild->setMounted(true);

if ((commitSource == ShadowTreeCommitSource::React &&
ReactNativeFeatureFlags::
updateRuntimeShadowNodeReferencesOnCommit()) ||
(ReactNativeFeatureFlags::
updateRuntimeShadowNodeReferencesOnCommitThread() &&
ShadowNode::getUseRuntimeShadowNodeReferenceUpdateOnThread())) {

if (shouldUpdateMountedFlag) {
newChild->setMounted(true);
}

if (shouldUpdateRuntimeReference) {
newChild->updateRuntimeShadowNodeReference(newChild);
}

updateMountedFlag({}, newChild->getChildren(), commitSource);
}

// State 3: Unmount old children.
for (index = lastIndexAfterFirstStage; index < oldChildren.size(); index++) {
const auto& oldChild = oldChildren[index];
oldChild->setMounted(false);
updateMountedFlag(oldChild->getChildren(), {}, commitSource);
if (shouldUpdateMountedFlag) {
for (index = lastIndexAfterFirstStage; index < oldChildren.size();
index++) {
const auto& oldChild = oldChildren[index];
oldChild->setMounted(false);

updateMountedFlag(oldChild->getChildren(), {}, commitSource);
}
}
}
} // namespace facebook::react
Loading