Skip to content

Don't recycle Android views that still have a parent - #59864

Open
lazerg wants to merge 1 commit into
react:mainfrom
lazerg:fix/issue-59863-recycled-view-parent
Open

lazerg wants to merge 1 commit into
react:mainfrom
lazerg:fix/issue-59863-recycled-view-parent

Conversation

@lazerg

@lazerg lazerg commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Summary:

With view recycling on, a view can sit in the pool while it still has a parent. If that parent called startViewTransition on it and then left the window before endViewTransition, the parent drops the view from its disappearing children but keeps itself as view.getParent(). The existing removeView call in createViewInstance can't clear that, so the recycled view goes back to the mounting layer and addViewAt crashes with "The specified child already has a parent". react-native-screens hits this when it pops a screen.

Now createViewInstance only reuses a pooled view if its parent is gone after the removeView call, and creates a new view otherwise. Views pooled while still attached to a non-recycling parent are reused as before.

Fixes #59863

Changelog:

[ANDROID] [FIXED] - Fix "The specified child already has a parent" crash when a recycled view is still held by a parent's view transition

Test Plan:

Added testViewStillHeldByADetachedParentIsNotRecycled to BaseViewManagerTest. It holds a view with startViewTransition, removes it, detaches the parent from the window, drops the view, and adds the next created view to a new parent. Without the fix it throws IllegalStateException: The specified child already has a parent; with the fix it passes.

./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest

The full ReactAndroid unit test suite passes. format-check-java and format-check-kotlin are clean. I didn't run the reproducer app on a device.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 8, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 8, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] View recycling reuses a view that still has a parent: "The specified child already has a parent"

1 participant