mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Add a synchronization mechanism for the layout information kept in the root nodes on the React branch (#54836)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/54836 Changelog: [General][Added] Added a synchronization mechanism for the layout information between the React branch and the main branch of the ShadowTree Since layout constraints and layout context are being kept in the props of the `RootShadowNode`, it was possible for the JS revision merge to lose an update if it was being commited concurrently. Reviewed By: rubennorte Differential Revision: D88839901 fbshipit-source-id: f81d96dacf60b4e5da29da32ada468c967a2c9df
This commit is contained in:
1 parent
47e5e6c394
commit
c8d498d62d
2 files changed
+38
-3
No files matched your search
@@ -170,6 +170,37 @@ static std::shared_ptr<ShadowNode> progressState(
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Updates the layout context and layout metrics on the RootNode for commits
|
||||
* coming from React. The RootNode is managed outside of it, and may have been
|
||||
* modified concurrently with the React revision.
|
||||
*/
|
||||
static std::shared_ptr<RootShadowNode> progressRootLayoutInfo(
|
||||
const std::shared_ptr<RootShadowNode>& shadowNode,
|
||||
const RootShadowNode& baseShadowNode,
|
||||
const ShadowTreeCommitOptions& commitOptions) {
|
||||
if (commitOptions.source == ShadowTreeCommitSource::React ||
|
||||
commitOptions.source == ShadowTreeCommitSource::ReactRevisionMerge) {
|
||||
const auto& mainBranchRootProps = baseShadowNode.getConcreteProps();
|
||||
const auto& jsBranchRootProps = shadowNode->getConcreteProps();
|
||||
|
||||
if (mainBranchRootProps.layoutConstraints ==
|
||||
jsBranchRootProps.layoutConstraints &&
|
||||
mainBranchRootProps.layoutContext == jsBranchRootProps.layoutContext) {
|
||||
// The layout information kept in the JS branch is up to date.
|
||||
return shadowNode;
|
||||
}
|
||||
|
||||
const auto clonedNode = baseShadowNode.ShadowNode::clone(
|
||||
{.children = std::make_shared<
|
||||
const std::vector<std::shared_ptr<const ShadowNode>>>(
|
||||
shadowNode->getChildren())});
|
||||
return std::static_pointer_cast<RootShadowNode>(clonedNode);
|
||||
}
|
||||
|
||||
return shadowNode;
|
||||
}
|
||||
|
||||
ShadowTree::ShadowTree(
|
||||
SurfaceId surfaceId,
|
||||
const LayoutConstraints& layoutConstraints,
|
||||
@@ -330,6 +361,13 @@ CommitStatus ShadowTree::tryCommit(
|
||||
}
|
||||
}
|
||||
|
||||
if (ReactNativeFeatureFlags::enableFabricCommitBranching()) {
|
||||
newRootShadowNode = progressRootLayoutInfo(
|
||||
newRootShadowNode,
|
||||
*oldRevisionForStateProgression.rootShadowNode,
|
||||
commitOptions);
|
||||
}
|
||||
|
||||
// Run commit hooks.
|
||||
newRootShadowNode = delegate_.shadowTreeWillCommit(
|
||||
*this, oldRootShadowNode, newRootShadowNode, commitOptions);
|
||||
|
||||
Vendored
-3
@@ -242,10 +242,7 @@ describe('ShadowTreeBranching', () => {
|
||||
]);
|
||||
|
||||
// Commit made from React - it should mount the final React tree
|
||||
// NOTE: The RootView update should not be included here, fixed
|
||||
// in a following diff
|
||||
expect(root.takeMountingManagerLogs()).toEqual([
|
||||
'Update {type: "RootView", nativeID: (root)}',
|
||||
'Update {type: "View", nativeID: "view"}',
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user