From 9eafec48f3f9c45b49fda4c8f1850d4bb8f81925 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 23 Sep 2024 04:57:17 -0700 Subject: [PATCH] Unbreak RN_SHADOW_TREE_INTROSPECTION flag (#46589) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46589 This is a useful too for debugging ShadowTree mutations, but was broken due to some recent build changes. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D63099720 fbshipit-source-id: 9ae5ee062ef9a6a99b2517e4eedd286cd6259fbe --- .../renderer/mounting/Differentiator.cpp | 1 + .../renderer/mounting/MountingCoordinator.cpp | 19 ++++++++++++------- .../renderer/mounting/MountingCoordinator.h | 1 - .../renderer/mounting/stubs/StubViewTree.cpp | 8 ++++---- .../renderer/mounting/stubs/StubViewTree.h | 2 +- .../react/renderer/mounting/stubs/stubs.h | 4 ++-- .../react/renderer/scheduler/Scheduler.cpp | 5 ----- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp index 761644ee204..9a29c126368 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp @@ -12,6 +12,7 @@ #include #include #include + #include "ShadowView.h" #ifdef DEBUG_LOGS_DIFFER diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/MountingCoordinator.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/MountingCoordinator.cpp index 8e21794b4e3..6f0fdb22979 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/MountingCoordinator.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/MountingCoordinator.cpp @@ -6,6 +6,11 @@ */ #include "MountingCoordinator.h" + +#include +#include +#include +#include #include "updateMountedFlag.h" #ifdef RN_SHADOW_TREE_INTROSPECTION @@ -13,12 +18,6 @@ #include #endif -#include - -#include -#include -#include - namespace facebook::react { MountingCoordinator::MountingCoordinator(const ShadowTreeRevision& baseRevision) @@ -104,6 +103,9 @@ std::optional MountingCoordinator::pullTransaction( } // Override case +#ifdef RN_SHADOW_TREE_INTROSPECTION + bool didOverridePullTransaction = false; +#endif for (const auto& delegate : mountingOverrideDelegates_) { auto mountingOverrideDelegate = delegate.lock(); auto shouldOverridePullTransaction = mountingOverrideDelegate && @@ -130,6 +132,9 @@ std::optional MountingCoordinator::pullTransaction( transaction = mountingOverrideDelegate->pullTransaction( surfaceId_, number_, telemetry, std::move(mutations)); +#ifdef RN_SHADOW_TREE_INTROSPECTION + didOverridePullTransaction = true; +#endif } } @@ -148,7 +153,7 @@ std::optional MountingCoordinator::pullTransaction( // If the transaction was overridden, we don't have a model of the shadow // tree therefore we cannot validate the validity of the mutation // instructions. - if (!shouldOverridePullTransaction && lastRevision_.has_value()) { + if (!didOverridePullTransaction && lastRevision_.has_value()) { auto stubViewTree = buildStubViewTreeWithoutUsingDifferentiator( *lastRevision_->rootShadowNode); diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/MountingCoordinator.h b/packages/react-native/ReactCommon/react/renderer/mounting/MountingCoordinator.h index 7ffe41a508a..179f1e0ca65 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/MountingCoordinator.h +++ b/packages/react-native/ReactCommon/react/renderer/mounting/MountingCoordinator.h @@ -17,7 +17,6 @@ #include #include #include -#include "ShadowTreeRevision.h" #ifdef RN_SHADOW_TREE_INTROSPECTION #include diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubViewTree.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubViewTree.cpp index f8e82c1dbaf..82fc091c13f 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubViewTree.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubViewTree.cpp @@ -257,9 +257,9 @@ void StubViewTree::mutate(const ShadowViewMutationList& mutations) { google::FlushLogFiles(google::GLOG_INFO); } -std::ostream& StubViewTree::dumpTags(std::ostream& stream) { +std::ostream& StubViewTree::dumpTags(std::ostream& stream) const { for (const auto& pair : registry_) { - auto& stubView = *registry_.at(pair.first); + auto& stubView = *pair.second; stream << "[" << stubView.tag << "]##" << std::hash{}((ShadowView)stubView) << " "; } @@ -273,10 +273,10 @@ bool operator==(const StubViewTree& lhs, const StubViewTree& rhs) { << lhs.registry_.size() << " RHS: " << rhs.registry_.size(); LOG(ERROR) << "Tags in LHS: "; - lhs.dumpTagsHash(LOG(ERROR)); + lhs.dumpTags(LOG(ERROR)); LOG(ERROR) << "Tags in RHS: "; - rhs.dumpTagsHash(LOG(ERROR)); + rhs.dumpTags(LOG(ERROR)); }); return false; diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubViewTree.h b/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubViewTree.h index 7581cdf56d2..3fef1cc475f 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubViewTree.h +++ b/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubViewTree.h @@ -41,7 +41,7 @@ class StubViewTree { friend bool operator==(const StubViewTree& lhs, const StubViewTree& rhs); friend bool operator!=(const StubViewTree& lhs, const StubViewTree& rhs); - std::ostream& dumpTags(std::ostream& stream); + std::ostream& dumpTags(std::ostream& stream) const; bool hasTag(Tag tag) const { return registry_.find(tag) != registry_.end(); diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/stubs/stubs.h b/packages/react-native/ReactCommon/react/renderer/mounting/stubs/stubs.h index 2f3cd3740df..d0829f339e6 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/stubs/stubs.h +++ b/packages/react-native/ReactCommon/react/renderer/mounting/stubs/stubs.h @@ -8,8 +8,8 @@ #pragma once #include -#include "StubView.h" -#include "StubViewTree.h" +#include +#include namespace facebook::react { diff --git a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp index 188b23d8666..4b69f2f2b04 100644 --- a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp +++ b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp @@ -22,11 +22,6 @@ #include #include -#ifdef RN_SHADOW_TREE_INTROSPECTION -#include -#include -#endif - namespace facebook::react { Scheduler::Scheduler(