From 1482dd9e99b2ec59f4f1d765baaa3e96fafb2b2e Mon Sep 17 00:00:00 2001 From: Nick Lefever Date: Tue, 11 Mar 2025 12:42:46 -0700 Subject: [PATCH] Add assert for recycled views with parent (#49937) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49937 Adding an assert for recycled views still attached to their parent, which would lead to an exception when the view would be added to a new parent. Changelog: [Internal] Reviewed By: javache Differential Revision: D70922503 fbshipit-source-id: 7d4daf427306203d603c31999ab138b3aee08e83 --- .../com/facebook/react/uimanager/ViewManager.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java index b1d88ae7590..85ebd1fc6ed 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java @@ -12,6 +12,7 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.facebook.common.logging.FLog; +import com.facebook.infer.annotation.Assertions; import com.facebook.react.bridge.BaseJavaModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContext; @@ -257,6 +258,16 @@ public abstract class ViewManager if (recyclableViews != null) { T recyclableView = prepareToRecycleView(themedReactContext, view); if (recyclableView != null) { + Assertions.assertCondition( + recyclableView.getParent() == null, + "Recycled view [" + + view.getId() + + "] should not be attached to a parent. View: " + + view + + " Parent: " + + recyclableView.getParent() + + " ThemedReactContext: " + + themedReactContext); recyclableViews.push(recyclableView); } }