Fix const-correctness for ShadowNodeFamily (#55783)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/55783

Changelog: [Internal]

remove unnecessary const from ShadowNodeFamily. This allows us to get rid of a few mutable keywords.

Reviewed By: christophpurrer

Differential Revision: D90763777

fbshipit-source-id: 036c87ad504331507acb86b8e556d884c0a5d815
This commit is contained in:
Samuel Susla authored and meta-codesync[bot] committed 2026-02-27 07:44:49 -08:00
1 parent e5d720d98d
commit 178c30d7ac
7 files changed
+25 -25

No files matched your search

@@ -740,7 +740,7 @@ void FabricUIManagerBinding::schedulerDidRequestPreliminaryViewAllocation(
// to be destroyed if the ShadowNode is destroyed but it was never mounted
// on the screen.
if (shadowNode.getTraits().check(ShadowNodeTraits::Trait::FormsView)) {
shadowNode.getFamily().onUnmountedFamilyDestroyed(
shadowNode.getFamilyShared()->onUnmountedFamilyDestroyed(
[weakMountingManager =
std::weak_ptr(mountingManager)](const ShadowNodeFamily& family) {
if (auto mountingManager = weakMountingManager.lock()) {
@@ -89,7 +89,7 @@ class AnimatedModule : public NativeAnimatedModuleCxxSpec<AnimatedModule>, publi
struct ConnectAnimatedNodeToShadowNodeFamilyOp {
Tag nodeTag{};
std::shared_ptr<const ShadowNodeFamily> shadowNodeFamily{};
std::shared_ptr<ShadowNodeFamily> shadowNodeFamily{};
};
struct DisconnectAnimatedNodeFromViewOp {
@@ -236,7 +236,7 @@ void NativeAnimatedNodesManager::connectAnimatedNodeToView(
void NativeAnimatedNodesManager::connectAnimatedNodeToShadowNodeFamily(
Tag propsNodeTag,
std::shared_ptr<const ShadowNodeFamily> family) noexcept {
std::shared_ptr<ShadowNodeFamily> family) noexcept {
react_native_assert(propsNodeTag);
auto node = getAnimatedNode<PropsAnimatedNode>(propsNodeTag);
if (node != nullptr && family != nullptr) {
@@ -101,7 +101,7 @@ class NativeAnimatedNodesManager {
void connectAnimatedNodeToView(Tag propsNodeTag, Tag viewTag) noexcept;
void connectAnimatedNodeToShadowNodeFamily(Tag propsNodeTag, std::shared_ptr<const ShadowNodeFamily> family) noexcept;
void connectAnimatedNodeToShadowNodeFamily(Tag propsNodeTag, std::shared_ptr<ShadowNodeFamily> family) noexcept;
void disconnectAnimatedNodes(Tag parentTag, Tag childTag) noexcept;
@@ -59,7 +59,7 @@ RootShadowNode::Unshared RootShadowNode::clone(
void RootShadowNode::setInstanceHandle(
InstanceHandle::Shared instanceHandle) const {
getFamily().setInstanceHandle(instanceHandle);
getFamilyShared()->setInstanceHandle(instanceHandle);
}
} // namespace facebook::react
@@ -33,7 +33,7 @@ ShadowNodeFamily::ShadowNodeFamily(
componentHandle_(componentDescriptor.getComponentHandle()),
componentName_(componentDescriptor.getComponentName()) {}
void ShadowNodeFamily::setParent(const ShadowNodeFamily::Shared& parent) const {
void ShadowNodeFamily::setParent(const ShadowNodeFamily::Shared& parent) {
react_native_assert(parent_.lock() == nullptr || parent_.lock() == parent);
if (hasParent_) {
return;
@@ -59,7 +59,7 @@ ComponentName ShadowNodeFamily::getComponentName() const {
return componentName_;
}
void ShadowNodeFamily::setMounted() const {
void ShadowNodeFamily::setMounted() {
hasBeenMounted_ = true;
}
@@ -68,7 +68,7 @@ const ComponentDescriptor& ShadowNodeFamily::getComponentDescriptor() const {
}
void ShadowNodeFamily::onUnmountedFamilyDestroyed(
std::function<void(const ShadowNodeFamily& family)> callback) const {
std::function<void(const ShadowNodeFamily& family)> callback) {
onUnmountedFamilyDestroyedCallback_ = std::move(callback);
}
@@ -89,7 +89,7 @@ InstanceHandle::Shared ShadowNodeFamily::getInstanceHandle() const {
}
void ShadowNodeFamily::setInstanceHandle(
InstanceHandle::Shared& instanceHandle) const {
InstanceHandle::Shared& instanceHandle) {
instanceHandle_ = instanceHandle;
}
@@ -144,7 +144,7 @@ State::Shared ShadowNodeFamily::getMostRecentState() const {
return mostRecentState_;
}
void ShadowNodeFamily::setMostRecentState(const State::Shared& state) const {
void ShadowNodeFamily::setMostRecentState(const State::Shared& state) {
std::unique_lock lock(mutex_);
/*
@@ -175,7 +175,7 @@ std::shared_ptr<const State> ShadowNodeFamily::getMostRecentStateIfObsolete(
void ShadowNodeFamily::dispatchRawState(
StateUpdate&& stateUpdate,
EventQueue::UpdateMode updateMode) const {
EventQueue::UpdateMode updateMode) {
auto eventDispatcher = eventDispatcher_.lock();
if (!eventDispatcher) {
return;
@@ -41,8 +41,8 @@ struct ShadowNodeFamilyFragment {
*/
class ShadowNodeFamily final : public jsi::NativeState {
public:
using Shared = std::shared_ptr<const ShadowNodeFamily>;
using Weak = std::weak_ptr<const ShadowNodeFamily>;
using Shared = std::shared_ptr<ShadowNodeFamily>;
using Weak = std::weak_ptr<ShadowNodeFamily>;
using AncestorList =
std::vector<std::pair<std::reference_wrapper<const ShadowNode> /* parentNode */, int /* childIndex */>>;
@@ -58,7 +58,7 @@ class ShadowNodeFamily final : public jsi::NativeState {
* This is not technically thread-safe, but practically it mutates the object
* only once (and the model enforces that this first call is not concurrent).
*/
void setParent(const ShadowNodeFamily::Shared &parent) const;
void setParent(const ShadowNodeFamily::Shared &parent);
/*
* Returns a handle (or name) associated with the component.
@@ -90,23 +90,23 @@ class ShadowNodeFamily final : public jsi::NativeState {
* @param callback will be executed when an unmounted instance of
* ShadowNodeFamily is destroyed.
*/
void onUnmountedFamilyDestroyed(std::function<void(const ShadowNodeFamily &family)> callback) const;
void onUnmountedFamilyDestroyed(std::function<void(const ShadowNodeFamily &family)> callback);
/*
* Sets and gets the most recent state.
*/
std::shared_ptr<const State> getMostRecentState() const;
void setMostRecentState(const std::shared_ptr<const State> &state) const;
void setMostRecentState(const std::shared_ptr<const State> &state);
/**
* Mark this ShadowNodeFamily as mounted.
*/
void setMounted() const;
void setMounted();
/*
* Dispatches a state update with given priority.
*/
void dispatchRawState(StateUpdate &&stateUpdate, EventQueue::UpdateMode updateMode) const;
void dispatchRawState(StateUpdate &&stateUpdate, EventQueue::UpdateMode updateMode);
/*
* Holds currently applied native props. `nullptr` if setNativeProps API is
@@ -122,7 +122,7 @@ class ShadowNodeFamily final : public jsi::NativeState {
jsi::Value getInstanceHandle(jsi::Runtime &runtime) const;
InstanceHandle::Shared getInstanceHandle() const;
void setInstanceHandle(InstanceHandle::Shared &instanceHandle) const;
void setInstanceHandle(InstanceHandle::Shared &instanceHandle);
/**
* Override destructor to call onUnmountedFamilyDestroyedCallback() for
@@ -142,10 +142,10 @@ class ShadowNodeFamily final : public jsi::NativeState {
std::shared_ptr<const State> getMostRecentStateIfObsolete(const State &state) const;
EventDispatcher::Weak eventDispatcher_;
mutable std::shared_ptr<const State> mostRecentState_;
std::shared_ptr<const State> mostRecentState_;
mutable std::shared_mutex mutex_;
mutable std::function<void(ShadowNodeFamily &family)> onUnmountedFamilyDestroyedCallback_ = nullptr;
std::function<void(ShadowNodeFamily &family)> onUnmountedFamilyDestroyedCallback_ = nullptr;
/*
* Deprecated.
@@ -160,7 +160,7 @@ class ShadowNodeFamily final : public jsi::NativeState {
/*
* Weak reference to the React instance handle
*/
mutable InstanceHandle::Shared instanceHandle_;
InstanceHandle::Shared instanceHandle_;
/*
* `EventEmitter` associated with all nodes of the family.
@@ -184,18 +184,18 @@ class ShadowNodeFamily final : public jsi::NativeState {
/*
* Points to a family of all parent nodes of all nodes of the family.
*/
mutable ShadowNodeFamily::Weak parent_{};
ShadowNodeFamily::Weak parent_{};
/*
* Represents a case where `parent_` is `nullptr`.
* For optimization purposes only.
*/
mutable bool hasParent_{false};
bool hasParent_{false};
/*
* Determines if the ShadowNodeFamily was ever mounted on the screen.
*/
mutable bool hasBeenMounted_{false};
bool hasBeenMounted_{false};
};
} // namespace facebook::react