From fa44c46e37baabc5664e860ac83c90cfdc9f4d68 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Fri, 18 Sep 2020 16:35:46 -0700 Subject: [PATCH] Fix flattening/unflattening case on Android Summary: There are cases where we Delete+Create a node in the same frame. Practically, the new differ should prevent this, but we don't want to rely on that necessarily. See comments for further justification on why deleteView can do less work overall. In reparenting cases, this causes crashes because dropView removes *and deletes* children that shouldn't necessarily be deleted. Changelog: [Internal] Reviewed By: shergin Differential Revision: D23775453 fbshipit-source-id: c577c5af8c27cfb185d527f0afd8aeb08ee3a5fe --- .../react/fabric/mounting/MountingManager.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java index 4629668d494..41cf97c71fb 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java @@ -577,13 +577,15 @@ public class MountingManager { return; } - View view = viewState.mView; - - if (view != null) { - dropView(view, false); - } else { - mTagToViewState.remove(reactTag); - } + // To delete we simply remove the tag from the registry. + // In the past we called dropView here, but we want to rely on either + // (1) the correct set of MountInstructions being sent to the platform + // and/or (2) dropView being called by stopSurface. + // If Views are orphaned at this stage and leaked, it's a problem in + // the differ or LayoutAnimations, not MountingManager. + // Additionally, as documented in `dropView`, we cannot always trust a + // view's children to be up-to-date. + mTagToViewState.remove(reactTag); } @UiThread