mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
125 lines
3.3 KiB
C++
125 lines
3.3 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include "MountingCoordinator.h"
|
|
|
|
#ifdef RN_SHADOW_TREE_INTROSPECTION
|
|
#include <glog/logging.h>
|
|
#include <sstream>
|
|
#endif
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <react/mounting/Differentiator.h>
|
|
#include <react/mounting/ShadowViewMutation.h>
|
|
#include <react/utils/TimeUtils.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
MountingCoordinator::MountingCoordinator(ShadowTreeRevision baseRevision)
|
|
: surfaceId_(baseRevision.getRootShadowNode().getSurfaceId()),
|
|
baseRevision_(baseRevision) {
|
|
#ifdef RN_SHADOW_TREE_INTROSPECTION
|
|
stubViewTree_ = stubViewTreeFromShadowNode(baseRevision_.getRootShadowNode());
|
|
#endif
|
|
}
|
|
|
|
SurfaceId MountingCoordinator::getSurfaceId() const {
|
|
return surfaceId_;
|
|
}
|
|
|
|
void MountingCoordinator::push(ShadowTreeRevision &&revision) const {
|
|
{
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
|
|
assert(revision.getNumber() > baseRevision_.getNumber());
|
|
assert(
|
|
!lastRevision_.has_value() ||
|
|
revision.getNumber() != lastRevision_->getNumber());
|
|
|
|
if (!lastRevision_.has_value() ||
|
|
lastRevision_->getNumber() < revision.getNumber()) {
|
|
lastRevision_ = std::move(revision);
|
|
}
|
|
}
|
|
|
|
signal_.notify_all();
|
|
}
|
|
|
|
void MountingCoordinator::revoke() const {
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
// We have two goals here.
|
|
// 1. We need to stop retaining `ShadowNode`s to not prolong their lifetime
|
|
// to prevent them from overliving `ComponentDescriptor`s.
|
|
// 2. A possible call to `pullTransaction()` should return empty optional.
|
|
baseRevision_.rootShadowNode_.reset();
|
|
lastRevision_.reset();
|
|
}
|
|
|
|
bool MountingCoordinator::waitForTransaction(
|
|
std::chrono::duration<double> timeout) const {
|
|
std::unique_lock<std::mutex> lock(mutex_);
|
|
return signal_.wait_for(
|
|
lock, timeout, [this]() { return lastRevision_.has_value(); });
|
|
}
|
|
|
|
better::optional<MountingTransaction> MountingCoordinator::pullTransaction()
|
|
const {
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
|
|
if (!lastRevision_.has_value()) {
|
|
return {};
|
|
}
|
|
|
|
number_++;
|
|
|
|
auto telemetry = lastRevision_->getTelemetry();
|
|
telemetry.willDiff();
|
|
|
|
auto mutations = calculateShadowViewMutations(
|
|
baseRevision_.getRootShadowNode(), lastRevision_->getRootShadowNode());
|
|
|
|
telemetry.didDiff();
|
|
|
|
#ifdef RN_SHADOW_TREE_INTROSPECTION
|
|
stubViewTree_.mutate(mutations);
|
|
auto stubViewTree =
|
|
stubViewTreeFromShadowNode(lastRevision_->getRootShadowNode());
|
|
|
|
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_);
|
|
lastRevision_.reset();
|
|
|
|
return MountingTransaction{
|
|
surfaceId_, number_, std::move(mutations), telemetry};
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|