Skip to content

Commit

Permalink
Guard FlatList getItemCount() against incorrect data type
Browse files Browse the repository at this point in the history
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
  • Loading branch information
NickGerleman authored and roryabraham committed Aug 17, 2022
1 parent 54f5383 commit 5a56e99
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Libraries/Lists/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
};

_getItemCount = (data: ?Array<ItemT>): number => {
if (data) {
if (Array.isArray(data)) {
const numColumns = numColumnsOrDefault(this.props.numColumns);
return numColumns > 1 ? Math.ceil(data.length / numColumns) : data.length;
} else {
Expand Down

0 comments on commit 5a56e99

Please sign in to comment.