Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Fix CREATE mutations being dropped by merging transactions #53313

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
diff --git a/node_modules/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp b/node_modules/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp
index 572fb3d..0efa1ed 100644
--- a/node_modules/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp
+++ b/node_modules/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp
@@ -468,7 +468,7 @@ void Binding::schedulerDidFinishTransaction(
mountingTransaction->getSurfaceId();
});

- if (pendingTransaction != pendingTransactions_.end()) {
+ if (pendingTransaction != pendingTransactions_.end() && pendingTransaction->canMergeWith(*mountingTransaction)) {
pendingTransaction->mergeWith(std::move(*mountingTransaction));
} else {
pendingTransactions_.push_back(std::move(*mountingTransaction));
diff --git a/node_modules/react-native/ReactCommon/react/renderer/mounting/MountingTransaction.cpp b/node_modules/react-native/ReactCommon/react/renderer/mounting/MountingTransaction.cpp
index d7dd1bc..d95d779 100644
--- a/node_modules/react-native/ReactCommon/react/renderer/mounting/MountingTransaction.cpp
+++ b/node_modules/react-native/ReactCommon/react/renderer/mounting/MountingTransaction.cpp
@@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

+#include <set>
+
#include "MountingTransaction.h"

namespace facebook::react {
@@ -54,4 +56,21 @@ void MountingTransaction::mergeWith(MountingTransaction&& transaction) {
telemetry_ = std::move(transaction.telemetry_);
}

+bool MountingTransaction::canMergeWith(MountingTransaction& transaction) {
+ std::set<Tag> deletedTags;
+ for (const auto& mutation : mutations_) {
+ if (mutation.type == ShadowViewMutation::Type::Delete) {
+ deletedTags.insert(mutation.oldChildShadowView.tag);
+ }
+ }
+
+ for (const auto& mutation : transaction.getMutations()) {
+ if (mutation.type == ShadowViewMutation::Type::Create && deletedTags.contains(mutation.newChildShadowView.tag)) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
} // namespace facebook::react
diff --git a/node_modules/react-native/ReactCommon/react/renderer/mounting/MountingTransaction.h b/node_modules/react-native/ReactCommon/react/renderer/mounting/MountingTransaction.h
index 277e9f4..38629db 100644
--- a/node_modules/react-native/ReactCommon/react/renderer/mounting/MountingTransaction.h
+++ b/node_modules/react-native/ReactCommon/react/renderer/mounting/MountingTransaction.h
@@ -85,6 +85,14 @@ class MountingTransaction final {
*/
void mergeWith(MountingTransaction&& transaction);

+ /*
+ * Checks whether the two transactions can be safely merged. Due to
+ * reordering of mutations during mount, the sequence of
+ * REMOVE -> DELETE | CREATE -> INSERT (2 transactions) may get changed to
+ * INSERT -> REMOVE -> DELETE and the state will diverge from there.
+ */
+ bool canMergeWith(MountingTransaction& transaction);
+
private:
SurfaceId surfaceId_;
Number number_;
Loading