From 752e709b51eaaf16db9c3704654d98580948d181 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Fri, 18 Sep 2020 16:35:46 -0700 Subject: [PATCH] Additional differ test: flattening differ should not produce DELETE and CREATE mutation for the same tag in the same frame Summary: See additional assertion. Tests still pass, so no other change was necessary. Changelog: [Internal] Differential Revision: D23775553 fbshipit-source-id: 57d3191f25dd55ab4da189207f6d201a31b175e0 --- .../tests/ShadowTreeLifeCycleTest.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ReactCommon/react/renderer/mounting/tests/ShadowTreeLifeCycleTest.cpp b/ReactCommon/react/renderer/mounting/tests/ShadowTreeLifeCycleTest.cpp index 851231da95..46d2fc4c6c 100644 --- a/ReactCommon/react/renderer/mounting/tests/ShadowTreeLifeCycleTest.cpp +++ b/ReactCommon/react/renderer/mounting/tests/ShadowTreeLifeCycleTest.cpp @@ -5,11 +5,14 @@ * LICENSE file in the root directory of this source tree. */ +#include + #include #include #include #include +#include #include #include @@ -102,6 +105,25 @@ static void testShadowNodeTreeLifeCycle( auto mutations = calculateShadowViewMutations( *currentRootNode, *nextRootNode, useFlattener); + // If using flattener: make sure that in a single frame, a DELETE for a view is not + // followed by a CREATE for the same view. + if (useFlattener) { + std::vector deletedTags{}; + for (auto const& mutation : mutations) { + if (mutation.type == ShadowViewMutation::Type::Delete) { + deletedTags.push_back(mutation.oldChildShadowView.tag); + } + } + for (auto const& mutation : mutations) { + if (mutation.type == ShadowViewMutation::Type::Create) { + if (std::find(deletedTags.begin(), deletedTags.end(), mutation.newChildShadowView.tag) != deletedTags.end()) { + LOG(ERROR) << "Deleted tag was recreated in mutations list: [" << mutation.newChildShadowView.tag << "]"; + FAIL(); + } + } + } + } + // Mutating the view tree. viewTree.mutate(mutations);