Skip to content

Commit f9d3399

Browse files
authored
(cherry-pick) fix: Make node marking as removable safer (#8026)
Cherry-pick of the #8014
1 parent e90f10a commit f9d3399

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

packages/react-native-reanimated/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,24 @@ void UpdatesRegistryManager::unmarkNodeAsRemovable(Tag viewTag) {
5757

5858
void UpdatesRegistryManager::handleNodeRemovals(
5959
const RootShadowNode &rootShadowNode) {
60-
for (auto it = removableShadowNodes_.begin();
61-
it != removableShadowNodes_.end();) {
62-
const auto &shadowNode = it->second;
63-
const auto &family = shadowNode->getFamily();
64-
const auto &ancestors = family.getAncestors(rootShadowNode);
65-
66-
// Skip if the node hasn't been removed
67-
if (!ancestors.empty()) {
68-
++it;
60+
RemovableShadowNodes remainingShadowNodes;
61+
62+
for (const auto &[tag, shadowNode] : removableShadowNodes_) {
63+
if (!shadowNode) {
6964
continue;
7065
}
7166

72-
const auto tag = shadowNode->getTag();
73-
for (auto &registry : registries_) {
74-
registry->remove(tag);
67+
if (shadowNode->getFamily().getAncestors(rootShadowNode).empty()) {
68+
for (auto &registry : registries_) {
69+
registry->remove(tag);
70+
}
71+
staticPropsRegistry_->remove(tag);
72+
} else {
73+
remainingShadowNodes.emplace(tag, shadowNode);
7574
}
76-
staticPropsRegistry_->remove(tag);
77-
it = removableShadowNodes_.erase(it);
7875
}
76+
77+
removableShadowNodes_ = std::move(remainingShadowNodes);
7978
}
8079

8180
PropsMap UpdatesRegistryManager::collectProps() {

packages/react-native-reanimated/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ class UpdatesRegistryManager {
4545
#endif
4646

4747
private:
48+
using RemovableShadowNodes =
49+
std::unordered_map<Tag, std::shared_ptr<const ShadowNode>>;
50+
4851
mutable std::mutex mutex_;
4952
std::atomic<bool> isPaused_;
5053
std::atomic<bool> shouldCommitAfterPause_;
51-
std::unordered_map<Tag, std::shared_ptr<const ShadowNode>>
52-
removableShadowNodes_;
54+
RemovableShadowNodes removableShadowNodes_;
5355
std::vector<std::shared_ptr<UpdatesRegistry>> registries_;
5456
const std::shared_ptr<StaticPropsRegistry> staticPropsRegistry_;
5557

packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,15 @@ void ReanimatedModuleProxy::setViewStyle(
408408
void ReanimatedModuleProxy::markNodeAsRemovable(
409409
jsi::Runtime &rt,
410410
const jsi::Value &shadowNodeWrapper) {
411+
auto lock = updatesRegistryManager_->lock();
411412
auto shadowNode = shadowNodeFromValue(rt, shadowNodeWrapper);
412413
updatesRegistryManager_->markNodeAsRemovable(shadowNode);
413414
}
414415

415416
void ReanimatedModuleProxy::unmarkNodeAsRemovable(
416417
jsi::Runtime &rt,
417418
const jsi::Value &viewTag) {
419+
auto lock = updatesRegistryManager_->lock();
418420
updatesRegistryManager_->unmarkNodeAsRemovable(viewTag.asNumber());
419421
}
420422

0 commit comments

Comments
 (0)