From bb9917a580f286b0330617f68a5fb7a42b4de9da 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 only on layout (#44773) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44773 Changelog: [Internal] Update runtime shadow node references for cloning happening within `YogaLayoutableShadowNode` during layout. This will update the JS references to shadow nodes with the latest layout metrics used to render the component and improve layout cache usage on the next commit. Reviewed By: sammy-SC Differential Revision: D58000071 fbshipit-source-id: 373d41f37a81e81ab8f23006491027473493de61 --- .../components/view/YogaLayoutableShadowNode.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp index 1a64b95b16a..f7ee626491f 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -211,6 +212,11 @@ void YogaLayoutableShadowNode::adoptYogaChild(size_t index) { // TODO: At this point, React has wrong reference to the node. (T138668036) auto clonedChildNode = childNode.clone({}); + if (ReactNativeFeatureFlags:: + useRuntimeShadowNodeReferenceUpdateOnLayout()) { + childNode.transferRuntimeShadowNodeReference(clonedChildNode); + } + // Replace the child node with a newly cloned one in the children list. replaceChild(childNode, clonedChildNode, index); } @@ -518,6 +524,10 @@ YogaLayoutableShadowNode& YogaLayoutableShadowNode::cloneChildInPlace( ShadowNodeFragment::childrenPlaceholder(), childNode.getState()}); + if (ReactNativeFeatureFlags::useRuntimeShadowNodeReferenceUpdateOnLayout()) { + childNode.transferRuntimeShadowNodeReference(clonedChildNode); + } + replaceChild(childNode, clonedChildNode, layoutableChildIndex); return static_cast(*clonedChildNode); }