Skip to content

View recycling breaks due to fragment view transitions #3249

@hannojg

Description

@hannojg

Description

When a native view manager reuses native views, such as when turning on View Recycling, there can be crashes caused by the react-native mounting layer trying to add a recycled view which still has a parent attached.

The red view you can see in this video is a recycled view, so each screen will try to use the same native instance of the view:

Screen_Recording_20250924_151216_FabricExample.mp4
addViewAt: failed to insert view [1560] into parent [1564] at index 1
The specified child already has a parent. You must call removeView) on the child's parent first.

To fix this I believe we need to:

  • fix RNS endRemovalTransition in Screen.kt as its currently broken and not correctly ending view transitions
  • make changes in react-native core for handling "in-transition" views

I have a PR that tries to address that issue here:

Steps to reproduce

The reproduction can be seen here:

To test it out simply clone / checkout & build from this branch:

Note: In this reproduction i didn't turn on view reycling, but just always return the same native view instance. This is reproducing how view recycling behaves.

I have an additional reproduction with view recycling in the PoC PR for fixing this issue:

Snack or a link to a repository

https://github.com/hannojg/react-native-screens/tree/reproduction/view-recycling-crashing-on-screen-transitions

Screens version

latest main

React Native version

0.81.1

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Fabric (New Architecture)

Build type

Debug mode

Device

Real device

Device model

No response

Acknowledgements

Yes

Metadata

Metadata

Assignees

Labels

Platform: AndroidThis issue is specific to AndroidRepro providedA reproduction with a snack or repo is provided

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions