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
This commit is contained in:
Joshua Gross
2020-01-13 23:14:30 -08:00
committed by Facebook Github Bot
parent 442dd26873
commit 16ada9dfb0
@@ -9,6 +9,7 @@
#ifdef RN_SHADOW_TREE_INTROSPECTION
#include <glog/logging.h>
#include <sstream>
#endif
#include <condition_variable>
@@ -89,20 +90,27 @@ better::optional<MountingTransaction> 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_);