Skip to content

Commit 625d330

Browse files
tomekzawcipolleschi
authored andcommitted
Fix dynamic_cast (RTTI) by adding key function to ShadowNodeWrapper again (#45290)
Summary: This PR restores the virtual destructor for `ShadowNodeWrapper` which was added in #33500 and unfortunately removed in #40864. The virtual destructor here serves as a key function. Without a key function, `obj.hasNativeState<ShadowNodeWrapper>(rt)` **does not** work correctly between shared library boundaries on Android and always returns false. We need this pretty badly in third-party libraries like react-native-reanimated or react-native-gesture-handler. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [ANDROID] [FIXED] - Fix dynamic_cast (RTTI) for ShadowNodeWrapper when accessed by third-party libraries again Pull Request resolved: #45290 Test Plan: This patch fixes an issue in Reanimated's fabric-example app. Reviewed By: fabriziocucci Differential Revision: D59375554 Pulled By: javache fbshipit-source-id: 09f3eda89a67c26d6dacca3428e08d1b7138d350
1 parent 2d42024 commit 625d330

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

packages/react-native/ReactCommon/react/renderer/core/ShadowNode.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,4 +410,10 @@ SharedDebugStringConvertibleList ShadowNode::getDebugProps() const {
410410
}
411411
#endif
412412

413+
// Explicitly define destructors here, as they need to exist in order to act as
414+
// a "key function" for the ShadowNodeWrapper class -- this allows for RTTI to
415+
// work properly across dynamic library boundaries (i.e. dynamic_cast that is
416+
// used by getNativeState method)
417+
ShadowNodeWrapper::~ShadowNodeWrapper() = default;
418+
413419
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/core/ShadowNode.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ struct ShadowNodeWrapper : public jsi::NativeState {
282282
explicit ShadowNodeWrapper(ShadowNode::Shared shadowNode)
283283
: shadowNode(std::move(shadowNode)) {}
284284

285+
// The below method needs to be implemented out-of-line in order for the class
286+
// to have at least one "key function" (see
287+
// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vague-vtable)
288+
~ShadowNodeWrapper() override;
289+
285290
ShadowNode::Shared shadowNode;
286291
};
287292

0 commit comments

Comments
 (0)