Skip to content

FlatList rendering too much data, repeatedly #25825

@mrspeaker

Description

@mrspeaker

My app was being extremely janky whenever the FlatList first loaded - and it seemed to be rendering too much at once. I stripped it back to a very minimal project (only rendering a FlatList) and it appears that this behaviour is there too: rendering multiple times, and too much data.

However, I might be mistaken on how the component works and the issue could be elsewhere in my code.

React Native version:

    iOS SDK:
      Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
  IDEs:
    Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6
    react-native: 0.60.4 => 0.60.0
  npmGlobalPackages:
    react-native-cli: 0.1.4
    react-native: 0.5.0

Steps To Reproduce

  1. Create minimal app with code:
const data = [...Array(400)].map((_, i) => `a-${i}`);

const App = () => {
  return (
    <View style={{ height: 400 }}>
      <FlatList
        data={data}
        renderItem={({ item, index }) => {
          console.log(item, index);
          return (
            <Text>
              {item}:{index}
            </Text>
          );
        }}
        keyExtractor={(item, index) => item}
      />
    </View>
  );
};
  1. Watch debug log. You can see the console.login action here: https://www.youtube.com/watch?v=kTXgZcm0cvg

The console.log should only be called one time for each initial chunk of items to be rendered. However it is logging many times. First it logs from index 0 to 9 (the first 10 elements of the array) then it immediately logs again from 0 to 30 (which is more than enough to fill the view), then immediately again from 0 to 180, and immediately again from 0 to 226.

Describe what you expected to happen:

I expected it only log for the initial rendered items. If I set disableVirtualization: true then the logs work "correctly" - only rendering the first chunk until you scroll down... but I don't think that is recommended!

It seems that each item is re-rendered multiple times, and 226 elements are all rendered on the first page load . Though perhaps internally this is just a "first pass" and rendering is somehow deferred? Or the act of console.logging causing the rerenders?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugComponent: FlatListStaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions