From 16ada9dfb0b4152f36cd46b306f72ba93d2fce57 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Mon, 13 Jan 2020 23:14:30 -0800 Subject: [PATCH] Fix MountingCoordinator stub view tree printer Summary: On Android/when printing to logcat, output is truncated to a certain max length; outputting a massive string as a single log item will cause some of it to be truncated. In the case of the mutations list and shadow node description, most of it is truncated. Easy fix: split into lines and log each line. This isn't necessary on iOS but works fine. I also removed the conditional and changed to an assert. Most of the time when we're using this block of code, it's because we want to see all mutations; and unless we reintroduce a bug into the core, the assert is never hit and so (before this change) the conditional would never be true and we'd never see this output. It's more generally useful to be able to see this output if the `RN_SHADOW_TREE_INTROSPECTION` macro is defined. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D19378929 fbshipit-source-id: 2f5dffeef7608823ac1ba092090d8c2ab5e965e1 --- .../fabric/mounting/MountingCoordinator.cpp | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/ReactCommon/fabric/mounting/MountingCoordinator.cpp b/ReactCommon/fabric/mounting/MountingCoordinator.cpp index 72ed5637cf7..d0bf0dc2fb0 100644 --- a/ReactCommon/fabric/mounting/MountingCoordinator.cpp +++ b/ReactCommon/fabric/mounting/MountingCoordinator.cpp @@ -9,6 +9,7 @@ #ifdef RN_SHADOW_TREE_INTROSPECTION #include +#include #endif #include @@ -89,20 +90,27 @@ better::optional MountingCoordinator::pullTransaction() stubViewTree_.mutate(mutations); auto stubViewTree = stubViewTreeFromShadowNode(lastRevision_->getRootShadowNode()); - if (stubViewTree_ != stubViewTree) { - LOG(ERROR) << "Old tree:" - << "\n" - << baseRevision_.getRootShadowNode().getDebugDescription() - << "\n"; - LOG(ERROR) << "New tree:" - << "\n" - << lastRevision_->getRootShadowNode().getDebugDescription() - << "\n"; - LOG(ERROR) << "Mutations:" - << "\n" - << getDebugDescription(mutations, {}); - assert(false); + + std::string line; + + std::stringstream ssOldTree( + baseRevision_.getRootShadowNode().getDebugDescription()); + while (std::getline(ssOldTree, line, '\n')) { + LOG(ERROR) << "Old tree:" << line; } + + std::stringstream ssNewTree( + lastRevision_->getRootShadowNode().getDebugDescription()); + while (std::getline(ssNewTree, line, '\n')) { + LOG(ERROR) << "New tree:" << line; + } + + std::stringstream ssMutations(getDebugDescription(mutations, {})); + while (std::getline(ssMutations, line, '\n')) { + LOG(ERROR) << "Mutations:" << line; + } + + assert(stubViewTree_ == stubViewTree); #endif baseRevision_ = std::move(*lastRevision_);