Avoid mounting tree on mode change if it wasn't commited

Summary:
Changelog: [Internal]

Calls to `surfaceHandler.start()` and `setDisplayMode(DisplayMode::Visible)` in quick succession on different threads can cause a race condition between mount and commit operations.

The mountingCoordinator will try to mount an empty revision without any commits causing it to fail with:
```
TransactionTelemetry.cpp:108: function getCommitStartTime: assertion failed (commitStartTime_ != kTelemetryUndefinedTimePoint)
```
which is called from [Binding.cpp](https://www.internalfb.com/intern/diffusion/FBS/browse/master/xplat/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp?lines=791-791&blame=1).

This change avoids this initial commit by verifying we had at least 1 revision commited before mounting it.

Reviewed By: sammy-SC

Differential Revision: D27430174

fbshipit-source-id: d208d55f02cd218a316d6fea62d0106c2bcb4be8
This commit is contained in:
Andrei Shikov
2021-04-12 13:17:52 -07:00
committed by Facebook GitHub Bot
parent 214aaf2703
commit a17e3cf893
2 changed files with 6 additions and 2 deletions
@@ -248,7 +248,7 @@ ShadowTree::ShadowTree(
family));
currentRevision_ = ShadowTreeRevision{
rootShadowNode, ShadowTreeRevision::Number{0}, TransactionTelemetry{}};
rootShadowNode, INITIAL_REVISION, TransactionTelemetry{}};
mountingCoordinator_ =
std::make_shared<MountingCoordinator const>(currentRevision_);
@@ -275,7 +275,9 @@ void ShadowTree::setCommitMode(CommitMode commitMode) const {
revision = currentRevision_;
}
if (commitMode == CommitMode::Normal) {
// initial revision never contains any commits so mounting it here is
// incorrect
if (commitMode == CommitMode::Normal && revision.number != INITIAL_REVISION) {
mount(revision);
}
}
@@ -124,6 +124,8 @@ class ShadowTree final {
MountingCoordinator::Shared getMountingCoordinator() const;
private:
constexpr static ShadowTreeRevision::Number INITIAL_REVISION{0};
void mount(ShadowTreeRevision const &revision) const;
void emitLayoutEvents(