Skip to content

Commit

Permalink
Back out "Fabric: Strengthening StubView mutating validation"
Browse files Browse the repository at this point in the history
Summary:
Changelog: [internal]

Original commit changeset: 8c8a3d8e205c

Reviewed By: ShikaSD

Differential Revision: D24951341

fbshipit-source-id: b6109a45f1537a9edc702eafac1736e801fbedc9
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Nov 13, 2020
1 parent 58c80d4 commit 53862a1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
12 changes: 0 additions & 12 deletions ReactCommon/react/renderer/mounting/StubView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@
namespace facebook {
namespace react {

StubView::operator ShadowView() const {
auto shadowView = ShadowView{};
shadowView.componentName = componentName;
shadowView.componentHandle = componentHandle;
shadowView.tag = tag;
shadowView.props = props;
shadowView.eventEmitter = eventEmitter;
shadowView.layoutMetrics = layoutMetrics;
shadowView.state = state;
return shadowView;
}

void StubView::update(ShadowView const &shadowView) {
componentName = shadowView.componentName;
componentHandle = shadowView.componentHandle;
Expand Down
2 changes: 0 additions & 2 deletions ReactCommon/react/renderer/mounting/StubView.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class StubView final {
StubView() = default;
StubView(StubView const &stubView) = default;

operator ShadowView() const;

void update(ShadowView const &shadowView);

ComponentName componentName;
Expand Down
38 changes: 25 additions & 13 deletions ReactCommon/react/renderer/mounting/StubViewTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,30 @@ StubView const &StubViewTree::getRootStubView() const {
return *registry.at(rootTag);
}

void StubViewTree::mutate(ShadowViewMutationList const &mutations) {
/**
* ignoreDuplicateCreates: when stubs generates "fake" mutation instructions, in
* some cases it can produce too many "create" instructions. We ignore
* duplicates and treat them as noops. In the case of verifying actual diffing,
* that assert is left on.
*
* @param mutations
* @param ignoreDuplicateCreates
*/
void StubViewTree::mutate(
ShadowViewMutationList const &mutations,
bool ignoreDuplicateCreates) {
STUB_VIEW_LOG({ LOG(ERROR) << "StubView: Mutating Begin"; });
for (auto const &mutation : mutations) {
switch (mutation.type) {
case ShadowViewMutation::Create: {
STUB_VIEW_ASSERT(mutation.parentShadowView == ShadowView{});
STUB_VIEW_ASSERT(mutation.oldChildShadowView == ShadowView{});
STUB_VIEW_ASSERT(mutation.newChildShadowView.props);
auto stubView = std::make_shared<StubView>();
stubView->update(mutation.newChildShadowView);
auto tag = mutation.newChildShadowView.tag;
STUB_VIEW_LOG({ LOG(ERROR) << "StubView: Create: " << tag; });
STUB_VIEW_ASSERT(registry.find(tag) == registry.end());
if (!ignoreDuplicateCreates) {
STUB_VIEW_ASSERT(registry.find(tag) == registry.end());
}
registry[tag] = stubView;
break;
}
Expand All @@ -62,9 +73,6 @@ void StubViewTree::mutate(ShadowViewMutationList const &mutations) {
STUB_VIEW_ASSERT(mutation.newChildShadowView == ShadowView{});
auto tag = mutation.oldChildShadowView.tag;
STUB_VIEW_ASSERT(registry.find(tag) != registry.end());
auto stubView = registry[tag];
STUB_VIEW_ASSERT(
(ShadowView)(*stubView) == mutation.oldChildShadowView);
registry.erase(tag);
break;
}
Expand Down Expand Up @@ -129,15 +137,19 @@ void StubViewTree::mutate(ShadowViewMutationList const &mutations) {
STUB_VIEW_LOG({
LOG(ERROR) << "StubView: Update: " << mutation.newChildShadowView.tag;
});
STUB_VIEW_ASSERT(mutation.newChildShadowView.props);

// We don't have a strict requirement that oldChildShadowView has any
// data. In particular, LayoutAnimations can produce UPDATEs with only a
// new node.
STUB_VIEW_ASSERT(
mutation.newChildShadowView.tag == mutation.oldChildShadowView.tag);
mutation.newChildShadowView.tag ==
mutation.oldChildShadowView.tag ||
mutation.oldChildShadowView.tag == 0);

STUB_VIEW_ASSERT(
registry.find(mutation.newChildShadowView.tag) != registry.end());
auto oldStubView = registry[mutation.newChildShadowView.tag];
STUB_VIEW_ASSERT(
(ShadowView)(*oldStubView) == mutation.oldChildShadowView);
oldStubView->update(mutation.newChildShadowView);
auto stubView = registry[mutation.newChildShadowView.tag];
stubView->update(mutation.newChildShadowView);
break;
}
}
Expand Down
4 changes: 3 additions & 1 deletion ReactCommon/react/renderer/mounting/StubViewTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class StubViewTree {
StubViewTree() = default;
StubViewTree(ShadowView const &shadowView);

void mutate(ShadowViewMutationList const &mutations);
void mutate(
ShadowViewMutationList const &mutations,
bool ignoreDuplicateCreates = false);

StubView const &getRootStubView() const;

Expand Down
2 changes: 1 addition & 1 deletion ReactCommon/react/renderer/mounting/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ StubViewTree stubViewTreeFromShadowNode(ShadowNode const &rootShadowNode) {
ShadowNode::emptySharedShadowNodeSharedList()});

auto stubViewTree = StubViewTree(ShadowView(*emptyRootShadowNode));
stubViewTree.mutate(mutations);
stubViewTree.mutate(mutations, true);
return stubViewTree;
}

Expand Down

0 comments on commit 53862a1

Please sign in to comment.