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
This commit is contained in:
Nick Lefever
2024-06-03 20:25:46 -07:00
committed by Facebook GitHub Bot
parent 4806077457
commit bb9917a580
@@ -10,6 +10,7 @@
#include <logger/react_native_log.h>
#include <react/debug/flags.h>
#include <react/debug/react_native_assert.h>
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/components/view/ViewShadowNode.h>
#include <react/renderer/components/view/conversions.h>
@@ -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<YogaLayoutableShadowNode&>(*clonedChildNode);
}