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

Large Flatlist is not rendering all items #15990

Closed
stefan0s opened this issue Sep 18, 2017 · 45 comments
Closed

Large Flatlist is not rendering all items #15990

stefan0s opened this issue Sep 18, 2017 · 45 comments
Labels
Bug Component: FlatList Priority: Mid Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@stefan0s
Copy link

stefan0s commented Sep 18, 2017

Is this a bug report?

This seems to be a bug of the FlatList while trying to render many items (more that 60-70).

Have you read the Contributing Guidelines?

(Write your answer here.)

Environment

We are using macOS and the issue happen on both iphone and android

  1. react-native -v: 0.45.1
  2. node -v: 6.9.1
  3. npm -v: 3.10.8
  4. yarn --version:

Then, specify:

  • Target Platform: iOS, Android
  • Development Operating System: macOS
  • Build tools: Xcode, Android Studio

Steps to Reproduce

We are using FlatList to render Message Items and after the Flatlist has been rendered we are using scrollToBottom to go to the last item. The Flatlist is working without any issues when having about 20 items, but when we have many items it is NOT always rendering them and not display them at all. We are having an example with 80 items and sometimes is rendering all of them but most of the times is rendering about 40.

@padil
Copy link

padil commented Sep 18, 2017

This happens because it is a virtualized list and loads the array bit by bit

@laynemoseley
Copy link

Does it render them when you scroll? Or do they literally never show up?

@stefan0s
Copy link
Author

No it does not render at all. But it is doing the following when is not rendering all items, it shows a white space but when i touch it, it aligns properly to the last item (but the rest not rendered and never shown).

@drewhamlett
Copy link

@stefan0s have you disabled removeClippedSubviews ?

@evanjmg
Copy link

evanjmg commented Nov 17, 2017

+1 I get this also in Section List - it stops at 120 for some reason - I can paginate up to 6 pages of 20 - I console.log the data in there after a async load and it is more than 120.

@evanjmg
Copy link

evanjmg commented Nov 17, 2017

I solved my problem:
Never mutate or map over your props for list items. Simple maps or copies of the props will not work properly- you have to do all your logic in redux or before changing props and use data={this.props.data}.

@kpink224
Copy link
Contributor

@stefan0s If you haven't already looked into PureComponent or shouldComponentUpdate in relation to FlatList or VirtualizedList, read this: https://60devs.com/pure-component-in-react.html

There is a HUGE performance difference when you implement a customized shouldComponentUpdate function with each of your entries - assuming they are various React Components you are rendering.

@bolan9999
Copy link

FlatList and SectionList is bad performance. Try this,please. may be it is a surprise for you

https://github.com/bolan9999/react-native-largelist

@stale
Copy link

stale bot commented Feb 23, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Feb 23, 2018
@react-native-bot react-native-bot added Lists 📜 Ran Commands One of our bots successfully processed a command. labels Mar 14, 2018
@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 14, 2018
@nicolasdanelon
Copy link

Hi, I'm running react-native v0.52.8 and I have the same issue. Will this be fixed? or we have to use third party components?

@junchenjun
Copy link

junchenjun commented Jun 1, 2018

I am having a similar issue, but not even on large lists, sometimes it just only renders partial rows, and the rest of the data are all just blank which you can clearly see that the list left some blank space for the rest of the data, but just not rendering them.
This just happens sometimes, most of time it works perfect, very hard for me to find out where excatly went wrong.

@RWOverdijk
Copy link

We have the same issue on android and have to revert to ListView.

It does seem to render, the jumping of next batch being rendered is visible but at some point it just cuts off. The space is reserved but nothing is visible. In fact, inspecting it (react views) shows the space. Everything is in the tree, it just doesn't show (or shows transparent).

Note: When making the items considerably smaller (20 height) the entire list does render. So it looks like there's some sort of cut-off point.

@vinceprofeta
Copy link

Does anyone have a fix for this issue?

@nicolasdanelon
Copy link

Does anyone have a fix for this issue? (bis)

@clint-gitahi
Copy link

I'm having a similar issue on android not iOS, running react-native v0.55.4.

@simonas88
Copy link

I have the same issue on android, RN v0.56. List is only 13 items.

@is343
Copy link

is343 commented Sep 12, 2018

@RWOverdijk this worked, thanks.

I was having the same issue with long lists on ios. I have list items that can display more items on a button click. The flatlist would grow the the correct length/height, but would stop rendering at either 10 or 15 items, and only display a blank white area for the rest of the list.
Switching ios over to ListView fixed the display issue.

No issues on android with FlatList.

@adamalexander
Copy link

One word. RecyclerListView. fades into the shadows

@Lufedi
Copy link

Lufedi commented Oct 30, 2018

I decided to use ScrollView and rendering the list of items and header by myself, I know that this can have some performance problems but it works for me now.

<ScrollView >
<MyHeaderComponent/>         
          {
            items.map((item) => {
               return <MyRowComponent  item={item}/>
             })
           }
</ScrollView>

@simonas88
Copy link

simonas88 commented Nov 11, 2018

I solved the issue by removing flex style property from the container of renderItem. Perhaps this is worth reporting as a separate issue linked specifically with the problematic flex behavior 🤔

@Lufedi
Copy link

Lufedi commented Nov 11, 2018

@simonas88 it worked for me too

@janiokq
Copy link

janiokq commented Nov 22, 2018

If it's a performance problem caused by listview
You can try this library
react-native-nlist

@kuriel-trivu
Copy link

kuriel-trivu commented Jan 23, 2019

For partial shown short list: added those values to FlatList and problem gone:

<FlatList style={{ flex: 0 }}
                    initialNumToRender={data.length}

honestly i don't know which one fixes the problem or if works for large data.

@grabbou
Copy link
Contributor

grabbou commented Mar 19, 2019

CC: @sahrens does the workaround to set flex to 0 sounds familiar to you?

@ezailWang
Copy link

remove getItemLayout property settings works for me

@mgcrea
Copy link

mgcrea commented Apr 26, 2019

I have the issue where only the initial buffer is rendered and no other items (left blank when scrolling). Can confirm it has something to do with getItemLayout in my case, but can't remove it as it's needed to scroll to index. {flex: 0} does not solve it.

What is strange is that it works in a storybook (minimal use case) but not inside the app (maybe react-navigation related?). Also in my case the <FlatList /> is inside a <Modal />

Only workaround so far is initialNumToRender={1000}... Not great!

edit: Another thing that fixes it is to add debug={true} prop on the <FlatList/>, not sure if it helps.

Looking at the code it looks like the culprit might be this line in Libraries/Lists/VirtualizedList.js:

const onLayout =
      /* $FlowFixMe(>=0.68.0 site=react_native_fb) This comment suppresses an
       * error found when Flow v0.68 was deployed. To see the error delete this
       * comment and run Flow. */
      getItemLayout && !parentProps.debug && !fillRateHelper.enabled()
        ? undefined
        : this.props.onLayout;

Not sure what it is supposed to optimize away...

edit : Can confirm that bypassing this ternary (eg. const onLayout = this.props.onLayout fixes it for me. Maybe I should open another issue?

@nicolasdanelon
Copy link

@mgcrea are you wrapping the <FlatList /> with a <ScrollView /> ?

<Modal {...modalProps}>
   <ScrollView {...viewProps}> <FlatList {..listProps} /> </ScrollView>
</Modal>

@sahrens
Copy link
Contributor

sahrens commented Apr 29, 2019

Wrapping in ScrollView and long running animations are the two main sources I've seen for issues like this.

8f186b8 should fix the latter in many cases.

I don't think this Issue is actionable unless someone can provide a repro, e.g. in snack.

@mgcrea
Copy link

mgcrea commented Apr 29, 2019

@nicolasdanelon could have been that since I had a tree looking like: <ScrollView><Button /><Modal><FlatList /></Modal></ScrollView but swapped the <ScrollView /> for a <View /> and it did not fixed it.

Here is the preview of the component/bug:

Screen Capture 2019-04-29 at 19 29 49

And a Preview of the Tree after swapping the Form's <ScrollView />:

Screenshot 2019-04-29 at 18 10 10

Will try to setup a repro on Snack soon, for now I have the workaround of patching the VirtualizedList source that does the job (hopefully without nasty side effects!). Thanks!

@1323shell
Copy link

1323shell commented May 4, 2019

You just need to add attribute initialNumToRender in your Flatlist. Example:

<Flatlist
    data={array}
    initialNumToRender={array.length}
    renderItem={({ item }) => <ListItem item={item} />}
/>

@mhtkar
Copy link

mhtkar commented May 11, 2019

initialNumToRender worked for me

@akhileshagrhari
Copy link

We had this issue of FlatList not rendering some of the items, even after scrolling some of the items were just not rendered. Only some external state change managed to cause the FlatList to render (often just partially).

After a lot of digging, I found out that a long-running animation was causing this issue. Animations seem to cause FlatList to delay item rendering by default, so we managed to fix this by adding a parameter isInteraction: false to the ongoing animation:

Animated.timing(this.controlValue, {
    to: someValue,
    useNativeDriver: true,
    isInteraction: false,
}).start()

After this, FlatList no longer waited for the animation to finish, and was rendering everything as expected.

Note, that basically any animation within your app can cause this, not just the ones within FlatList.

solved for me, thanks @satellink

@EitanJoseph
Copy link

yes @kuriel-trivu has the right solution

@abhi-nahi
Copy link

Sorry to say, but I didn't find any solution working for me. I'm still facing the same issue.

@tvler
Copy link

tvler commented Oct 3, 2019

Unfortunately not using getItemLayout has proven to be the most stable way to render FlatLists for my team. I've made this eslint rule to enforce the prop isn't being used until this issue can be resolved – seems like tooling like this is a good way to enforce not using flaky parts of react native. https://github.com/tvler/eslint-plugin-react-native-no-get-item-layout-prop-on-virtualized-list

@abdullahizzuddiin
Copy link

I have try all solution stated above. But no one has worked for my case. It is so weird. Look at my app react-devtools capture. Only first item that wont rendered. it is not always first item that wont rendered sometimes other item of my list.

I try to figure out by put log on constructor of my item component. Only on component that not rendered, the log not printed.

Flat List Render

Zoom into first item render

Any idea to solve this issue?

@hotaryuzaki
Copy link

hotaryuzaki commented Oct 17, 2019

For partial shown short list: added those values to FlatList and problem gone:

<FlatList style={{ flex: 0 }}
                    initialNumToRender={data.length}

honestly i don't know which one fixes the problem or if works for large data.

it works..
why????????

my problem is i found that 1 category not showing all datas, it has 92 data but only showing 15.
my initialNumToRender is 15, but set initialNumToRender to data length solve the problem.
it would be impact to performance right?

i tried change initialNumToRender value to other number, so i can confirm it is a bug from initialNumToRender in Flatlist.
i suspect is only render the first initial data then stop, because if i set initialNumToRender to 15 it is only showing 15, if set 2 is only showing 2.

right now i set to 20 because performance considerations, it solved the problem too.

@hotaryuzaki
Copy link

Unfortunately not using getItemLayout has proven to be the most stable way to render FlatLists for my team. I've made this eslint rule to enforce the prop isn't being used until this issue can be resolved – seems like tooling like this is a good way to enforce not using flaky parts of react native. https://github.com/tvler/eslint-plugin-react-native-no-get-item-layout-prop-on-virtualized-list

so this the main issue??
the getItemLayout in VirtualizedList?

@rushikeshc7
Copy link

@ezailWang This worked for me. Thanks dude.

remove getItemLayout property settings works for me

@israr2018
Copy link

I faced this issue as well. initialNumToRender={data.length} does not work for me.

@jjhampton
Copy link

@satellink I think your suggestion (setting useInteraction: false) on animations may have solved this for me. 🤞

From the RN docs on
https://facebook.github.io/react-native/docs/animated#loop: "In addition, loops can prevent VirtualizedList-based components from rendering more rows while the animation is running. You can pass isInteraction: false in the child animation config to fix this."

@stale
Copy link

stale bot commented Apr 29, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Apr 29, 2020
@stale
Copy link

stale bot commented May 7, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed May 7, 2020
@facebook facebook locked as resolved and limited conversation to collaborators May 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Component: FlatList Priority: Mid Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests