From 5a56e99d15fdd675e258ed4f48df5d1132d72ef5 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Wed, 27 Jul 2022 17:11:43 -0700 Subject: [PATCH] Guard FlatList getItemCount() against incorrect `data` type Summary: If FlatList is passed non-array data it will return `undefined` as the result of `getItemCount()` to VirtualizedList. This change makes it return `0` instead, to signify there are no valid items to attempt to accces. There are a set of invariants on properties passed to FlatList, to curb incorrect types at runtime, but there is existing code which runs into the condition. Changelog: [Internal][Fixed] - Guard FlatList getItemCount() against non-array data Reviewed By: javache Differential Revision: D38198351 fbshipit-source-id: 9efd0df7eeeba17078e2c838d470c4b0d621b9a0 --- Libraries/Lists/FlatList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Lists/FlatList.js b/Libraries/Lists/FlatList.js index a56962691c09c9..11d34d07bdc90c 100644 --- a/Libraries/Lists/FlatList.js +++ b/Libraries/Lists/FlatList.js @@ -511,7 +511,7 @@ class FlatList extends React.PureComponent, void> { }; _getItemCount = (data: ?Array): number => { - if (data) { + if (Array.isArray(data)) { const numColumns = numColumnsOrDefault(this.props.numColumns); return numColumns > 1 ? Math.ceil(data.length / numColumns) : data.length; } else {