@@ -80,98 +80,98 @@ void MountingCoordinator::resetLatestRevision() const {
80
80
lastRevision_.reset ();
81
81
}
82
82
83
- #ifdef RN_SHADOW_TREE_INTROSPECTION
84
- void MountingCoordinator::validateTransactionAgainstStubViewTree (
85
- ShadowViewMutationList const &mutations,
86
- bool assertEquality) const {
87
- std::string line;
88
-
89
- std::stringstream ssMutations (getDebugDescription (mutations, {}));
90
- while (std::getline (ssMutations, line, ' \n ' )) {
91
- LOG (ERROR) << " Mutations:" << line;
92
- }
93
-
94
- stubViewTree_.mutate (mutations);
95
- auto stubViewTree =
96
- stubViewTreeFromShadowNode (lastRevision_->getRootShadowNode ());
83
+ better::optional<MountingTransaction> MountingCoordinator::pullTransaction ()
84
+ const {
85
+ std::lock_guard<std::mutex> lock (mutex_);
97
86
98
- std::stringstream ssOldTree (
99
- baseRevision_.getRootShadowNode ().getDebugDescription ());
100
- while (std::getline (ssOldTree, line, ' \n ' )) {
101
- LOG (ERROR) << " Old tree:" << line;
102
- }
87
+ auto transaction = better::optional<MountingTransaction>{};
103
88
104
- std::stringstream ssNewTree (
105
- lastRevision_->getRootShadowNode ().getDebugDescription ());
106
- while (std::getline (ssNewTree, line, ' \n ' )) {
107
- LOG (ERROR) << " New tree:" << line;
108
- }
89
+ // Base case
90
+ if (lastRevision_.has_value ()) {
91
+ number_++;
109
92
110
- if (assertEquality) {
111
- assert (stubViewTree_ == stubViewTree);
112
- }
113
- }
114
- #endif
93
+ auto telemetry = lastRevision_->getTelemetry ();
115
94
116
- better::optional<MountingTransaction> MountingCoordinator::pullTransaction ()
117
- const {
118
- std::lock_guard<std::mutex> lock (mutex_);
95
+ telemetry.willDiff ();
119
96
120
- auto mountingOverrideDelegate = mountingOverrideDelegate_.lock ();
97
+ auto mutations = calculateShadowViewMutations (
98
+ baseRevision_.getRootShadowNode (), lastRevision_->getRootShadowNode ());
121
99
122
- bool shouldOverridePullTransaction = mountingOverrideDelegate &&
123
- mountingOverrideDelegate->shouldOverridePullTransaction ();
100
+ telemetry.didDiff ();
124
101
125
- if (!shouldOverridePullTransaction && !lastRevision_.has_value ()) {
126
- return {};
127
- }
102
+ baseRevision_ = std::move (*lastRevision_);
103
+ lastRevision_.reset ();
128
104
129
- number_++;
130
-
131
- ShadowViewMutation::List diffMutations{};
132
- auto telemetry =
133
- (lastRevision_.hasValue () ? lastRevision_->getTelemetry ()
134
- : TransactionTelemetry{});
135
- if (!lastRevision_.hasValue ()) {
136
- telemetry.willLayout ();
137
- telemetry.didLayout ();
138
- telemetry.willCommit ();
139
- telemetry.didCommit ();
140
- }
141
- telemetry.willDiff ();
142
- if (lastRevision_.hasValue ()) {
143
- diffMutations = calculateShadowViewMutations (
144
- baseRevision_.getRootShadowNode (),
145
- lastRevision_->getRootShadowNode (),
146
- enableReparentingDetection_);
105
+ transaction = MountingTransaction{
106
+ surfaceId_, number_, std::move (mutations), telemetry};
147
107
}
148
- telemetry.didDiff ();
149
108
150
- better::optional<MountingTransaction> transaction{};
109
+ // Override case
110
+ auto mountingOverrideDelegate = mountingOverrideDelegate_.lock ();
111
+ auto shouldOverridePullTransaction = mountingOverrideDelegate &&
112
+ mountingOverrideDelegate->shouldOverridePullTransaction ();
151
113
152
- // The override delegate can provide custom mounting instructions,
153
- // even if there's no `lastRevision_`. Consider cases of animation frames
154
- // in between React tree updates.
155
114
if (shouldOverridePullTransaction) {
115
+ auto mutations = ShadowViewMutation::List{};
116
+ auto telemetry = TransactionTelemetry{};
117
+
118
+ if (transaction.has_value ()) {
119
+ mutations = transaction->getMutations ();
120
+ telemetry = transaction->getTelemetry ();
121
+ } else {
122
+ telemetry.willLayout ();
123
+ telemetry.didLayout ();
124
+ telemetry.willCommit ();
125
+ telemetry.didCommit ();
126
+ }
127
+
156
128
transaction = mountingOverrideDelegate->pullTransaction (
157
- surfaceId_, number_, telemetry, std::move (diffMutations));
158
- } else if (lastRevision_.hasValue ()) {
159
- transaction = MountingTransaction{
160
- surfaceId_, number_, std::move (diffMutations), telemetry};
129
+ surfaceId_, number_, telemetry, std::move (mutations));
161
130
}
162
131
163
- if (lastRevision_.hasValue ()) {
164
132
#ifdef RN_SHADOW_TREE_INTROSPECTION
165
- // Only validate non-animated transactions - it's garbage to validate
166
- // animated transactions, since the stub view tree likely won't match
167
- // the committed tree during an animation.
168
- this ->validateTransactionAgainstStubViewTree (
169
- transaction->getMutations (), !shouldOverridePullTransaction);
170
- #endif
171
-
172
- baseRevision_ = std::move (*lastRevision_);
173
- lastRevision_.reset ();
133
+ if (transaction.has_value ()) {
134
+ // We have something to validate.
135
+ auto mutations = transaction->getMutations ();
136
+
137
+ // No matter what the source of the transaction is, it must be able to
138
+ // mutate the existing stub view tree.
139
+ stubViewTree_.mutate (mutations);
140
+
141
+ // If the transaction was overridden, we don't have a model of the shadow
142
+ // tree therefore we cannot validate the validity of the mutation
143
+ // instructions.
144
+ if (!shouldOverridePullTransaction) {
145
+ auto line = std::string{};
146
+
147
+ auto stubViewTree =
148
+ stubViewTreeFromShadowNode (baseRevision_.getRootShadowNode ());
149
+
150
+ if (stubViewTree_ != stubViewTree) {
151
+ std::stringstream ssOldTree (
152
+ baseRevision_.getRootShadowNode ().getDebugDescription ());
153
+ while (std::getline (ssOldTree, line, ' \n ' )) {
154
+ LOG (ERROR) << " Old tree:" << line;
155
+ }
156
+
157
+ std::stringstream ssMutations (getDebugDescription (mutations, {}));
158
+ while (std::getline (ssMutations, line, ' \n ' )) {
159
+ LOG (ERROR) << " Mutations:" << line;
160
+ }
161
+
162
+ std::stringstream ssNewTree (
163
+ lastRevision_->getRootShadowNode ().getDebugDescription ());
164
+ while (std::getline (ssNewTree, line, ' \n ' )) {
165
+ LOG (ERROR) << " New tree:" << line;
166
+ }
167
+ }
168
+
169
+ assert (
170
+ (stubViewTree_ == stubViewTree) &&
171
+ " Incorrect set of mutations detected." );
172
+ }
174
173
}
174
+ #endif
175
175
176
176
return transaction;
177
177
}
0 commit comments