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
https://github.com/user-attachments/assets/db7e7eae-7840-4a58-a84b-25534e67f2ef
Steps to reproduce
- Open the repro app
- Navigate to the flatlist screen
- Press header back button
- 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
- Update react-native-screens to fix crash Rendering FlashList inside KeyboardAwareScrollView was causing an error that crashes the application, see https://github.com/software-mansion/react-native-scr... — committed to Dosbodoke/chooselife by Dosbodoke 2 years ago
- Update react-native-screens to fix crash (#60) Rendering FlashList inside KeyboardAwareScrollView was causing an error that crashes the application, see https://github.com/software-mansion/react-nati... — committed to Dosbodoke/chooselife by Dosbodoke 2 years ago
- Stable version uploaded to Play Store (#79) * Fix bottom sheet handle color on light mode * Improve auth * Refactored profile screen * Added dark mode switcher and fixed some styles * Added page ... — committed to Dosbodoke/chooselife by Dosbodoke 2 years ago
Temporarily add this to FlatList to fix the issue:
Got this workaround from: https://github.com/software-mansion/react-native-screens/issues/2282
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
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.0https://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 onv4.6.0So, a quick summary should be:
If you are on new arch and using
v0.76use rn-screenv4.4.0If you are on new arch and usingv0.77usev4.6.0Do not usev4.5.0Feel free to suggest any editions.
This id worked thanks
worked for me
Anyone who also face this issue and using older react native versions. For now downgrade to
react-native-screens 4.4.0fixed 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
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 to3.35.0and it did fix it, thanks @alduzy 🙂The issue should be gone in
3.35.0. If the problem persists please attach a reproduction code.it worked!!! thanks man.
@c-info use this prop in your Flatlist:
removeClippedSubviews: false,
Is the screen that you are moving back using FlatList/FlashList? I read something on this thread about setting ‘removeClippedSubviews={false}’
@Sowmiya13G Use 4.4
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 recommend choosing the appropriate RN Screens version published at the library’s github repository. Refer here
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