From ba43dd25135b7cb8306fe693f037187d8e5ab15b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Fri, 17 Nov 2023 10:12:42 -0800 Subject: [PATCH] Revert D51394187: delete ShadowNodeFamily::instanceHandle_ Differential Revision: D51394187 Original commit changeset: 3add711a3954 Original Phabricator Diff: D51394187 fbshipit-source-id: 881fb82c949fef05f001fec57f62911a3a5dc482 --- .../ReactCommon/react/renderer/core/ShadowNode.cpp | 7 ++++++- .../ReactCommon/react/renderer/core/ShadowNodeFamily.cpp | 1 + .../ReactCommon/react/renderer/core/ShadowNodeFamily.h | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactCommon/react/renderer/core/ShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/core/ShadowNode.cpp index 5d8da6fe6b6ca5..d51cb8ff2311a1 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/ShadowNode.cpp @@ -173,7 +173,12 @@ const SharedEventEmitter& ShadowNode::getEventEmitter() const { } jsi::Value ShadowNode::getInstanceHandle(jsi::Runtime& runtime) const { - return family_->eventEmitter_->getEventTarget()->getInstanceHandle(runtime); + auto instanceHandle = family_->instanceHandle_; + if (instanceHandle == nullptr) { + return jsi::Value::null(); + } + + return instanceHandle->getInstanceHandle(runtime); } Tag ShadowNode::getTag() const { diff --git a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.cpp b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.cpp index 88143a9d0c0e47..0e73b0a5cf3687 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.cpp @@ -26,6 +26,7 @@ ShadowNodeFamily::ShadowNodeFamily( : eventDispatcher_(std::move(eventDispatcher)), tag_(fragment.tag), surfaceId_(fragment.surfaceId), + instanceHandle_(fragment.instanceHandle), eventEmitter_(std::move(eventEmitter)), componentDescriptor_(componentDescriptor), componentHandle_(componentDescriptor.getComponentHandle()), diff --git a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h index c4a0b4face1b12..dc5dbc815317f0 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h @@ -132,6 +132,11 @@ class ShadowNodeFamily final { */ const SurfaceId surfaceId_; + /* + * Weak reference to the React instance handle + */ + InstanceHandle::Shared const instanceHandle_; + /* * `EventEmitter` associated with all nodes of the family. */