From 34431272c3e9eb736071dac00a2ed2072eca0b96 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Sat, 12 Oct 2024 00:39:21 -0700 Subject: [PATCH] Move execution of ReactNativeFeatureFlags::enableDeletionOfUnmountedViews() out of destructor (#46993) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46993 Calling ReactNativeFeatureFlags::enableDeletionOfUnmountedViews() from the destructor increases the chance of accessing ReactNativeFeatureFlags during the tear down of React Native. We are moving this call into the contructor of the object which always happen on the js thread changelog: [internal] internal Reviewed By: rubennorte Differential Revision: D64190029 fbshipit-source-id: 377b85e8ff0704db0f6603662f595b75a6705693 --- .../ReactCommon/react/renderer/core/ShadowNodeFamily.cpp | 8 +++++--- .../ReactCommon/react/renderer/core/ShadowNodeFamily.h | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.cpp b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.cpp index d9cd860098c..a189a538453 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.cpp @@ -31,7 +31,9 @@ ShadowNodeFamily::ShadowNodeFamily( eventEmitter_(std::move(eventEmitter)), componentDescriptor_(componentDescriptor), componentHandle_(componentDescriptor.getComponentHandle()), - componentName_(componentDescriptor.getComponentName()) {} + componentName_(componentDescriptor.getComponentName()), + isDeletionOfUnmountedViewsEnabled_( + ReactNativeFeatureFlags::enableDeletionOfUnmountedViews()) {} void ShadowNodeFamily::setParent(const ShadowNodeFamily::Shared& parent) const { react_native_assert(parent_.lock() == nullptr || parent_.lock() == parent); @@ -77,8 +79,8 @@ Tag ShadowNodeFamily::getTag() const { } ShadowNodeFamily::~ShadowNodeFamily() { - if (ReactNativeFeatureFlags::enableDeletionOfUnmountedViews() && - !hasBeenMounted_ && onUnmountedFamilyDestroyedCallback_ != nullptr) { + if (isDeletionOfUnmountedViewsEnabled_ && !hasBeenMounted_ && + onUnmountedFamilyDestroyedCallback_ != nullptr) { onUnmountedFamilyDestroyedCallback_(*this); } } diff --git a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h index c0621377419..44453ccd490 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h @@ -196,6 +196,12 @@ class ShadowNodeFamily final { * Determines if the ShadowNodeFamily was ever mounted on the screen. */ mutable bool hasBeenMounted_{false}; + + /* + * Determines if Views that were never mounted on the screen should be deleted + * when the shadow node family is destroyed. + */ + const bool isDeletionOfUnmountedViewsEnabled_; }; } // namespace facebook::react