Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlatList is not rendering the complete list of items. #39421

Open
gokulravi2010 opened this issue Sep 13, 2023 · 25 comments
Open

FlatList is not rendering the complete list of items. #39421

gokulravi2010 opened this issue Sep 13, 2023 · 25 comments
Labels
Component: FlatList Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Triage 🔍

Comments

@gokulravi2010
Copy link

Description

It seems that there is a bug on the react-native flatlist while trying to render a list of items. Sometimes only some of the list items are displayed.
When there are interactions such as state changes, there is an update in the list and all the list items are displayed properly.

React Native Version

0.72.4

Output of npx react-native info

System:
Binaries:
Node:
version: 16.20.0
Yarn:
version: 1.22.19
npm:
version: 8.19.4

SDKs:
iOS SDK:
Platforms:
- DriverKit 22.2
- iOS 16.2
- macOS 13.1
- tvOS 16.1
- watchOS 9.1
Android SDK:
API Levels:
- "23"
- "28"
- "29"
- "30"
- "31"
- "32"
- "33"
- "34"
Build Tools:
- 29.0.2
- 30.0.2
- 30.0.3
- 31.0.0
- 33.0.0
- 34.0.0

Languages:
Java:
version: 11.0.15
Ruby:
version: 2.6.10
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.72.4
wanted: 0.72.4
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false

Steps to reproduce

We are using a FlatList to render a List of 500-1000 items based on a dynamic response. We are updating the states based on navigations and data filter.
However sometimes in the initial load of the page the Flatlist is rendering only 5 items and it is unable to render the remaining items when scrolling down.

When there are state changes after initial load of data, there is an update in the list and all the data items are displayed properly.

Snack, screenshot, or link to a repository

Attaching an example link only for depicting the flatlist configuration we use.
https://stackoverflow.com/questions/77036267/issue-flatlist-rendering-only-few-items-in-the-list

@github-actions github-actions bot added the Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. label Sep 13, 2023
@github-actions
Copy link

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

@lunaleaps
Copy link
Contributor

lunaleaps commented Sep 13, 2023

The StackOverflow link mentions removing removeClippedSubviews prop, have you tried that?

Can you provide more details about when it happens as it sounds not consistent.

There a couple things that sound weird to me.

  1. You providing an initialNumToRender of 10 and it only rendering 5 items -- can you provide a minimal repro of that? I haven't seen this behavior before
  2. It sounds like the scroll handler isn't getting triggered to batch the next update to render. Can you investigate if that is the case?

@singlamayank
Copy link

I'm also facing the same issue after upgrading to React Native to 0.72.4. FlatList is only rendering the number of items defined in 'initialNumToRender'. Rest of the items are not getting rendered, so I'm not able to scroll over those items.

@prateekraj
Copy link

prateekraj commented Sep 15, 2023

I'm also facing the same problem. I upgraded my react native from 0.63..3 to 0.72.4 and suddenly my Flatlist stopped rendering views. Before upgrade It was working absolutely fine.

<FlatList
horizontal
data={reviewQuestionArray}
disableIntervalMomentum={true}
ref={ref => (this.flatListRef = ref)}
// onViewableItemsChanged={this.onViewableItemsChanged }
viewabilityConfig={{
itemVisiblePercentThreshold: 50,
}}
onMomentumScrollEnd={this.onScrollEnd}
onEndReached={this.loadMoreData}
//disableVirtualization = {true}
initialNumToRender={1}
pagingEnabled
keyExtractor={keyExtractor}
getItemLayout={getItemLayout}
maxToRenderPerBatch={10}
windowSize={3}
snapToInterval={WINDOW_WIDTH}
renderItem={({ item, index }) =>

}
/>

@prateekraj
Copy link

prateekraj commented Sep 17, 2023

I'm also facing the same problem. I upgraded my react native from 0.63..3 to 0.72.4 and suddenly my Flatlist stopped rendering views. Before upgrade It was working absolutely fine.

<FlatList horizontal data={reviewQuestionArray} disableIntervalMomentum={true} ref={ref => (this.flatListRef = ref)} // onViewableItemsChanged={this.onViewableItemsChanged } viewabilityConfig={{ itemVisiblePercentThreshold: 50, }} onMomentumScrollEnd={this.onScrollEnd} onEndReached={this.loadMoreData} //disableVirtualization = {true} initialNumToRender={1} pagingEnabled keyExtractor={keyExtractor} getItemLayout={getItemLayout} maxToRenderPerBatch={10} windowSize={3} snapToInterval={WINDOW_WIDTH} renderItem={({ item, index }) => } />

My flatlist worked finally. You have to put an empty check before you render flatlist "reviewQuestionArray.length >0".

(reviewQuestionArray.length>0) &&
<FlatList
horizontal
data={reviewQuestionArray}
disableIntervalMomentum={true}
ref={ref => (this.flatListRef = ref)}
// onViewableItemsChanged={this.onViewableItemsChanged }
viewabilityConfig={{
itemVisiblePercentThreshold: 50,
}}
onMomentumScrollEnd={this.onScrollEnd}
onEndReached={this.loadMoreData}
//disableVirtualization = {true}
initialNumToRender={1}
pagingEnabled
keyExtractor={keyExtractor}
getItemLayout={getItemLayout}
maxToRenderPerBatch={10}
windowSize={3}
snapToInterval={WINDOW_WIDTH}
renderItem={({ item, index }) =>

}
/>

@nartjie101
Copy link

nartjie101 commented Oct 3, 2023

Based on the answers above, I created a custom component to fix the issue:

import React, { useCallback } from 'react';
import { FlatList, ScrollView, FlatListProps } from 'react-native';

interface Props extends FlatListProps<any> {}

export default React.memo<Props>((props: Props) => {
    const { ListEmptyComponent, ...rest } = props;

    const renderComponent = useCallback((component: any) => {
        return component ? (component instanceof Function ? component() : component) : null;
    }, []);

    return rest.data && rest.data.length === 0 ? (
        <ScrollView {...rest}>
            {renderComponent(rest.ListHeaderComponent)}
            {renderComponent(ListEmptyComponent)}
            {renderComponent(rest.ListFooterComponent)}
        </ScrollView>
    ) : (
        <FlatList {...rest} />
    );
});

@Sheoranmohit
Copy link

I am facing the same issue after upgrading to version 0.72.4. The FlatList component is not rendering all the items. By default, it only renders around 10 items. If I specify a number in the 'initialNumToRender' prop, then only that number of items is displayed.

@Levminer
Copy link

Levminer commented Nov 1, 2023

Same issue only the first ~10 items gets rendered on 0.72.5, reverted back to 0.71.14, FlatList works there as expected.

@tlmader
Copy link

tlmader commented Nov 7, 2023

Running into the same issue on 0.72.5 on web only. For me, removing the ListHeaderComponent prop solves the issue, but I need my header content 😄

Update: Removing React Native Element's Skeleton component from our header fixes this somehow? I recommend removing one component at a time and see if you have any luck.

@imamrobani
Copy link

in my case for the first time, all the data was successfully rendered, but when I tried to go back until I exited the application and opened it again, only 10 data were displayed, and there was an empty space below, no data was displayed, but when I killed the app and opened it again, all of them running back to normal

I don't know why this is, this happened when I updated to React Native 0.71.XX
so now I still stay at RN 0.70.13
Previously I was using version 69.3

Has anyone experienced something similar in RN 0.71.XX?

@andreialecu
Copy link

Related: #36766

@tamirla
Copy link

tamirla commented Nov 29, 2023

in my case for the first time, all the data was successfully rendered, but when I tried to go back until I exited the application and opened it again, only 10 data were displayed, and there was an empty space below, no data was displayed, but when I killed the app and opened it again, all of them running back to normal

I don't know why this is, this happened when I updated to React Native 0.71.XX so now I still stay at RN 0.70.13 Previously I was using version 69.3

Has anyone experienced something similar in RN 0.71.XX?

Yes, we also had this issue in 0.71.12
Based on the answers above we upgraded to 0.71.14 and it fixed the problem

@Aryk
Copy link

Aryk commented Dec 13, 2023

I'm also facing the same problem. I upgraded my react native from 0.63..3 to 0.72.4 and suddenly my Flatlist stopped rendering views. Before upgrade It was working absolutely fine.
<FlatList horizontal data={reviewQuestionArray} disableIntervalMomentum={true} ref={ref => (this.flatListRef = ref)} // onViewableItemsChanged={this.onViewableItemsChanged } viewabilityConfig={{ itemVisiblePercentThreshold: 50, }} onMomentumScrollEnd={this.onScrollEnd} onEndReached={this.loadMoreData} //disableVirtualization = {true} initialNumToRender={1} pagingEnabled keyExtractor={keyExtractor} getItemLayout={getItemLayout} maxToRenderPerBatch={10} windowSize={3} snapToInterval={WINDOW_WIDTH} renderItem={({ item, index }) => } />

My flatlist worked finally. You have to put an empty check before you render flatlist "reviewQuestionArray.length >0".

(reviewQuestionArray.length>0) && <FlatList horizontal data={reviewQuestionArray} disableIntervalMomentum={true} ref={ref => (this.flatListRef = ref)} // onViewableItemsChanged={this.onViewableItemsChanged } viewabilityConfig={{ itemVisiblePercentThreshold: 50, }} onMomentumScrollEnd={this.onScrollEnd} onEndReached={this.loadMoreData} //disableVirtualization = {true} initialNumToRender={1} pagingEnabled keyExtractor={keyExtractor} getItemLayout={getItemLayout} maxToRenderPerBatch={10} windowSize={3} snapToInterval={WINDOW_WIDTH} renderItem={({ item, index }) =>

} />

I wouldn't recommend the empty check because you might have a ListEmptyComponent...see my solution here.

@laurent22
Copy link

We have the same problem in React Native 0.71.10 in the two FlatLists we have.

@viper4595
Copy link

in my case for the first time, all the data was successfully rendered, but when I tried to go back until I exited the application and opened it again, only 10 data were displayed, and there was an empty space below, no data was displayed, but when I killed the app and opened it again, all of them running back to normal

I don't know why this is, this happened when I updated to React Native 0.71.XX so now I still stay at RN 0.70.13 Previously I was using version 69.3

Has anyone experienced something similar in RN 0.71.XX?

I face the same issue when using react native 0.72.4.

@emanusantos
Copy link

Same issue on 0.72.5

@imamrobani
Copy link

in my case for the first time, all the data was successfully rendered, but when I tried to go back until I exited the application and opened it again, only 10 data were displayed, and there was an empty space below, no data was displayed, but when I killed the app and opened it again, all of them running back to normal

I don't know why this is, this happened when I updated to React Native 0.71.XX so now I still stay at RN 0.70.13 Previously I was using version 69.3

Has anyone experienced something similar in RN 0.71.XX?

Finally I found a solution to this issue in my case.

This issue occurs when returning from a screen that has a loading skeleton, when I go back until the application exits, this issue occurs.
The library used is react-native-easy-content-loader and this is an outdated library, and this is what causes this issue to occur. then I replaced/deleted it and Flatlist ran again on 71.xx or above

After I checked, because there was animation, I had to make sure whether there was any animation running so it was interfering with the rendering process

maybe it could also be a reference for others.
and now my project using RN 0.72..8

@LouisWT
Copy link

LouisWT commented Jan 19, 2024

Same issue on react native 0.72.5

@100sarthak100
Copy link

Same issue in 0.73.4.

@Arman6117

This comment was marked as resolved.

@fcole90
Copy link

fcole90 commented Mar 27, 2024

Is this bug the same as #36766 (comment) ? 🤔

@LIND96
Copy link

LIND96 commented Apr 26, 2024

Same issue on 0.72.13 ☹️☹️☹️☹️☹️

@striwensko
Copy link

For people having the same issue another thing to try is to make sure you don't use margins, try padding instead. I had the same issue and was fixed when I stop using vertical margin and replaced by vertical padding

@d-o-2021
Copy link

I got this issue on RN v73.6 as well. I think there is an issue with flatlist rendering.
In my case I solved this by conditionally rendering flatlist on the basis of data length.
eg:

{data.length > 0 && <FlatList data={data} />

Hope this might help

@dmregister
Copy link

How we managed to find our issue was turning on the InteractionManager debug flag directly in the node_modules:
https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Interaction/InteractionManager.js#L28

From there, we were able to see interaction handles being created, but not cleared. When the interaction handles were not cleared, FlatList would not render any data as it waits for all interactions to clear before rendering. Every create needs a clear.

Specifically we used rn-range-slider and saw an issue with the implementation using a memo instead of a ref. The memo would re-render and create a new interaction handler leaving the pervious one open. Switching this to a ref fixed the issue for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: FlatList Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Triage 🔍
Projects
None yet
Development

No branches or pull requests