From a643e191f65f035d3b60bd78df92cb43ae05f69d Mon Sep 17 00:00:00 2001 From: Nick Lefever Date: Mon, 3 Jun 2024 20:25:46 -0700 Subject: [PATCH] Update runtime shadow node references when cloning within react native (#44770) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44770 Changelog: [Internal] Any shadow node cloning happening outside the execution of the UIManagerBinding `cloneNode` function should update references held to the shadow node to reference the latest revision. All shadow node cloning not requested by the JS runtime should update the references to those shadow nodes within the JS runtime so that these would hold the latest state updated outside of the React renderer (i.e. state data and layout metrics). This guarantees that the React renderer's current fiber tree holds references to the ShadowNode instances that acually were layed out and committed for rendering on the native side. Maintaining these references up to date on the JS current fiber tree allows to maximize layout cache usage on subsequent commits. Reviewed By: sammy-SC Differential Revision: D57860867 fbshipit-source-id: f13e3fa9ad501fb2c8a387fb58b6379d236d7c2d --- .../react/renderer/core/ConcreteComponentDescriptor.h | 1 + .../ReactCommon/react/renderer/uimanager/UIManager.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h b/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h index 653f7700efa..9e42b9b524a 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h @@ -78,6 +78,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor { const ShadowNode& sourceShadowNode, const ShadowNodeFragment& fragment) const override { auto shadowNode = std::make_shared(sourceShadowNode, fragment); + sourceShadowNode.transferRuntimeShadowNodeReference(shadowNode, fragment); adopt(*shadowNode); return shadowNode; diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp index f3b61507c5c..de2bf9c1fa3 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp @@ -153,6 +153,7 @@ std::shared_ptr UIManager::cloneNode( { .props = props, .children = children, + .runtimeShadowNodeReference = false, }); return clonedShadowNode;