Skip to content

Commit

Permalink
Move execution of ReactNativeFeatureFlags::enableDeletionOfUnmountedV…
Browse files Browse the repository at this point in the history
…iews() out of destructor (#46993)

Summary:

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
  • Loading branch information
mdvacca authored and facebook-github-bot committed Oct 12, 2024
1 parent 2fdf2e4 commit 955b9ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -77,8 +79,8 @@ Tag ShadowNodeFamily::getTag() const {
}

ShadowNodeFamily::~ShadowNodeFamily() {
if (ReactNativeFeatureFlags::enableDeletionOfUnmountedViews() &&
!hasBeenMounted_ && onUnmountedFamilyDestroyedCallback_ != nullptr) {
if (isDeletionOfUnmountedViewsEnabled_ && !hasBeenMounted_ &&
onUnmountedFamilyDestroyedCallback_ != nullptr) {
onUnmountedFamilyDestroyedCallback_(*this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 955b9ca

Please sign in to comment.