From bfa00a5d62063e2a82e6df7b15d5fb7361d95f58 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Mon, 10 Feb 2020 15:31:46 -0800 Subject: [PATCH] Fix ShadowNode.stateRevision value assignment Summary: # Problem We calculate `stateRevision_` in constructor from children, but children change after shadowNode is initialised and before it is sealed. So the `stateRevision_` we calculate in constructor can be incorrect. # Solution Recalculate `stateRevision_` whenever children change. This can happen in two methods `ShadowNode::replaceChild` and `ShadowNode::appendChild`. This diff implements this solution. Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D19813840 fbshipit-source-id: 8fc3b6601e4618f4ee5b322eebc230e0bbb92e3a --- ReactCommon/fabric/core/shadownode/ShadowNode.cpp | 4 ++++ ReactCommon/fabric/core/shadownode/ShadowNode.h | 9 ++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp index 6d9ea43bffb..3fe931d6651 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp @@ -178,6 +178,8 @@ void ShadowNode::appendChild(const ShadowNode::Shared &child) { nonConstChildren->push_back(child); child->family_->setParent(family_); + + stateRevision_ += child->getStateRevision(); } void ShadowNode::replaceChild( @@ -186,6 +188,8 @@ void ShadowNode::replaceChild( int suggestedIndex) { ensureUnsealed(); + stateRevision_ += newChild->getStateRevision() - oldChild.getStateRevision(); + cloneChildrenIfShared(); newChild->family_->setParent(family_); diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.h b/ReactCommon/fabric/core/shadownode/ShadowNode.h index 08de4454529..223d189c282 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.h +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.h @@ -171,12 +171,11 @@ class ShadowNode : public virtual Sealable, friend ShadowNodeFamily; /** - * This number is deterministically, statelessly recomputable (it's dependent - * only on the immutable properties stored in this class). It tells us the - * version of the state of the entire subtree, including this component and - * all descendants. + * This number is deterministically, statelessly recomputable . It tells us + * the version of the state of the entire subtree, including this component + * and all descendants. */ - int const stateRevision_; + int stateRevision_; /* * Clones the list of children (and creates a new `shared_ptr` to it) if