react-native-screens: Android - "cannot remove child at index X" error on new architecture

Description

When navigating back from a stack screen which contains a FlatList, the app throws a soft error:

Cannot remove child at index 9 from parent ViewGroup [106], only 10 children in parent. Warning: childCount may be incorrect!

null
image

https://github.com/user-attachments/assets/db7e7eae-7840-4a58-a84b-25534e67f2ef

Steps to reproduce

  1. Open the repro app
  2. Navigate to the flatlist screen
  3. Press header back button
  4. Observe error

Snack or a link to a repository

https://github.com/72days/TestNavFlatListIssues

Screens version

3.34.0

React Native version

0.75.2

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Fabric (New Architecture)

Build type

Debug mode

Device

Real device

Device model

Samsung S9 and Pixel 1

Acknowledgements

Yes

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 25
  • Comments: 66 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Temporarily add this to FlatList to fix the issue:

<FlatList
    data={images}
    numColumns={3}
    contentContainerStyle={[{paddingHorizontal: 10}, containerStyle]}
    renderItem={renderItem}
    removeClippedSubviews={false} // <- Add This
/>

Got this workaround from: https://github.com/software-mansion/react-native-screens/issues/2282

Issue still persists on 4.7.0-beta.4

4.5.0 works for me though.

Can you update your comment with which version of react are you using?

For new readers, here’s what I found…

rn v0.76 with new arch had an issue with nested lists that was crashing the applications, so the rn-screen team made a series of PR’s to mitigate it

  1. https://github.com/software-mansion/react-native-screens/pull/2307
  2. https://github.com/software-mansion/react-native-screens/pull/2383
  3. https://github.com/software-mansion/react-native-screens/pull/2495
  4. https://github.com/software-mansion/react-native-screens/pull/2531

These commits are avaiable on react-native-screens v4.3.0 that added https://github.com/software-mansion/react-native-screens/pull/2531 . You should be able to use v4.4.0 as also

But then rn v0.77 came out, the team rn-screens add support to it on v4.5.0 https://github.com/software-mansion/react-native-screens/pull/2581 . At some time rn 0.77 introduced a fix for this problem and the rn-screens team removed those changes that were a workound https://github.com/software-mansion/react-native-screens/commit/2aa278c8c5c39d697f636fa8c3781fc96f1a2e1b on v4.6.0

So, a quick summary should be:

If you are on new arch and using v0.76 use rn-screen v4.4.0 If you are on new arch and using v0.77 use v4.6.0 Do not use v4.5.0

Feel free to suggest any editions.

Issue still persists on 4.7.0-beta.4 4.5.0 works for me though.

Can you update your comment with which version of react are you using?

For new readers, here’s what I found…

rn v0.76 with new arch had an issue with nested lists that was crashing the applications, so the rn-screen team made a series of PR’s to mitigate it

  1. fix(Android): incorrect childCount in removeViewAt when using flatlist on fabric #2307
  2. fix(Android): going back on fabric with nested list #2383
  3. fix(Android): going back on fabric with removeClippedSubviews #2495
  4. fix(Android): prevent crash when we can not insert any subviews into child #2531

These commits are avaiable on react-native-screens v4.3.0 that added #2531 . You should be able to use v4.4.0 as also

But then rn v0.77 came out, the team rn-screens add support to it on v4.5.0 #2581 . At some time rn 0.77 introduced a fix for this problem and the rn-screens team removed those changes that were a workound 2aa278c on v4.6.0

So, a quick summary should be:

If you are on new arch and using v0.76 use rn-screen v4.4.0 If you are on new arch and using v0.77 use v4.6.0 Do not use v4.5.0

Feel free to suggest any editions.

This id worked thanks

react-native 0.76.5 and react-native-screens 4.2.0 is what worked for me. 4.3.0, 4.4.0, 4.5.0, 4.6.0 are all broken.

worked for me

Anyone who also face this issue and using older react native versions. For now downgrade to react-native-screens 4.4.0 fixed for me. make sure you remove ^ from version.

"react-native-screens": "4.4.0"

react-native 0.76.5 and react-native-screens 4.2.0 is what worked for me. 4.3.0, 4.4.0, 4.5.0, 4.6.0 are all broken.

They resolved this issue in the latest RN release . I am using these versions RN - 0.77.0 , React & React-dom - 18.2.0 and RN Screen - 4.2.0. If you are facing the issue again, i recommend using Flashlist by shopify for this purpose and tell me how is it ?

Facing this issue with react native 0.76.1, react native screens 3.35.0

facing this issue with “react-native-screens”: “^3.35.0”, and “react-native”: “0.76.0”,

Same issue RN: 0.76.5 React-native-screen: ^4.4.0 Screenshot_20250225_204703_Venus.jpg

I have found some temporary solution just get the latest or any stable version of RN Screens Currently I’m using 4.5.0 and it is working fine for me. Happy Coding : )

i changed its version to 4.5.0 and also 4.4.0 it didn’t work. How can i fix that someone know ?

You can use RN - 0.77.0 , React & React-dom - 18.2.0 and RN Screen - 4.2.0 to resolve this issue. They fixed this in latest update i think so.

Confirmed that this is fixed for me with RN 0.76.2 and RN Screens 4.2.0. Thank you for your help!

Same, seeing this issue in RN 0.76.1 and RN Screens 3.35.0

Had the issue with 3.34.0, just upgraded to 3.35.0 and it did fix it, thanks @alduzy 🙂

The issue should be gone in 3.35.0. If the problem persists please attach a reproduction code.

Temporarily add this to FlatList to fix the issue:

<FlatList data={images} numColumns={3} contentContainerStyle={[{paddingHorizontal: 10}, containerStyle]} renderItem={renderItem} removeClippedSubviews={false} // <- Add This /> Got this workaround from: #2282

it worked!!! thanks man.

@c-info use this prop in your Flatlist:

removeClippedSubviews: false,

If you are on new arch and using v0.76 use rn-screen v4.4.0 If you are on new arch and using v0.77 use v4.6.0 Do not use v4.5.0

I used exactly that, RN 0.76 and rn-screen v4.4.0 and still facing that issue, any suggestions?

Is the screen that you are moving back using FlatList/FlashList? I read something on this thread about setting ‘removeClippedSubviews={false}’

I use RN 0.76.6 and react-native-screen: 4.6.0 and get error

Bro, read the thread. I did a super detailed explanation some comments earlier that will fix your problem.

Good luck

<FlatList data={images} numColumns={3} contentContainerStyle={[{paddingHorizontal: 10}, containerStyle]} renderItem={renderItem} removeClippedSubviews={false} />

This line tempralily helped me to remove the issue to the Flatlist — removeClippedSubviews={false}

I’ve also experienced this issue using 4.6.0. Downgrading to 4.5.0 does solve it for me.

I actually had the issue with a production build, even though it was fine in Expo Go. (Expo does complain that I should be using 4.4.0, but had to upgrade due the ongoing pressable onPress issue). So I was just getting a white screen, and had to use adb debug to determine the error.

As others have mentioned, the issue occurs when navigation back from a screen that has a Flatlist on. The issue occurred on 6 out of the 7 screens that contain a flatlist in my app.

I have found some temporary solution just get the latest or any stable version of RN Screens Currently I’m using 4.5.0 and it is working fine for me. Happy Coding : )

I’m also facing the same issue in RN Screen : ‘^4.6.0’ ,RN 0.76.6

I’m also facing the same issue in RN Screen : ‘^4.3.0’ Is there any solution for this?Tôi cũng đang gặp phải vấn đề tương tự trong Màn hình RN: ‘^ 4.3.0’ Có giải pháp nào cho điều này không?

I recommend choosing the appropriate RN Screens version published at the library’s github repository. Refer here

Image

I’m using “react-native-screens”: “4.5.0”, I’d issue on “react-native-screens”:“^4.0.0” which installed latest 4.6.0 initially, which was causing the issue. I manually downgraded to previous working 4.5.0 version from my package-lock.json. It started working.

“react-native-screens”: “3.34.0”, to “3.35.0”, working for me

I just wanted to confirm that issue is resolved in v4.2.0.

Same issue in RN 0.76.1 and RNScreens 3.35.0. I also tried updating RNScreens to 4.1.0 and had the same result.

Facing this issue with RN 0.75.4 and react-native-screens - 3.34.0