Fix mutation sorting function

Summary:
The sorting function currently forms a partial ordering, not a total ordering. This can cause problems with certain sequences of immediate or conflicting mutations, leading to UI corruption or crashes.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D24002668

fbshipit-source-id: edc9b4c1e3104897cb0c5fd6da563ec43d800494
This commit is contained in:
Joshua Gross
2020-09-29 16:35:44 -07:00
committed by Facebook GitHub Bot
parent 521b16730d
commit ca51dc6288
@@ -308,6 +308,14 @@ static inline bool shouldFirstComeBeforeSecondMutation(
return true;
}
// Update comes last, before deletes
if (rhs.type == ShadowViewMutation::Type::Update) {
return true;
}
if (lhs.type == ShadowViewMutation::Type::Update) {
return false;
}
// Remove comes before insert
if (lhs.type == ShadowViewMutation::Type::Remove &&
rhs.type == ShadowViewMutation::Type::Insert) {
@@ -317,6 +325,16 @@ static inline bool shouldFirstComeBeforeSecondMutation(
lhs.type == ShadowViewMutation::Type::Insert) {
return false;
}
// Create comes before insert
if (lhs.type == ShadowViewMutation::Type::Create &&
rhs.type == ShadowViewMutation::Type::Insert) {
return true;
}
if (rhs.type == ShadowViewMutation::Type::Create &&
lhs.type == ShadowViewMutation::Type::Insert) {
return false;
}
} else {
// Make sure that removes on the same level are sorted - highest indices
// must come first.