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
This commit is contained in:
David Vacca
2024-10-12 00:39:21 -07:00
committed by Facebook GitHub Bot
parent 621622a5b1
commit 34431272c3
2 changed files with 11 additions and 3 deletions
@@ -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);
}
}
@@ -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