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

[2/2] Constrain data type in getItemLayout callback #36237

Closed
wants to merge 2 commits into from

Conversation

NickGerleman
Copy link
Contributor

@NickGerleman NickGerleman commented Feb 22, 2023

Summary:
This changes the data parameter type for getItemLayout from a mutable array (too lenient, even before), to a $ArrayLike, which is now the most constrained subset of data which may be passed to a FlatList.

We could do something more exact by adding another generic parameter to FlatList, but that would be likely be noticeably more breaking, since during testing I couldn't manage a pattern that both kept the same minimum number of generic arguments while keeping inference working.

Changelog:
[General][Breaking] - Constrain data type in getItemLayout callback

Differential Revision: D43466967

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner fb-exported labels Feb 22, 2023
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D43466967

@NickGerleman NickGerleman changed the title Constrain data type in getItemLayout callback [2/2] Constrain data type in getItemLayout callback Feb 22, 2023
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D43466967

NickGerleman added a commit to NickGerleman/react-native that referenced this pull request Feb 22, 2023
Summary:
Pull Request resolved: facebook#36237

This changes the data parameter type for `getItemCallback` from a mutable array (too lenient, even before), to a `$ArrayLike`, which is now the most constrained subset of data which may be passed to a FlatList.

We could do something more exact by adding another generic parameter to FlatList, but that would be likely be noticeably more breaking, since during testing I couldn't manage a pattern that both kept the same minimum number of generic arguments while keeping inference working.

Changelog:
[General][Breaking] - Constrain data type in `getItemLayout` callback

Differential Revision: D43466967

fbshipit-source-id: 853feeecc4ab2934f4f527a1db4464c09163102f
@analysis-bot
Copy link

analysis-bot commented Feb 22, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,458,851 +29
android hermes armeabi-v7a 7,782,068 +15
android hermes x86 8,934,722 +26
android hermes x86_64 8,791,822 +14
android jsc arm64-v8a 9,093,017 +13
android jsc armeabi-v7a 8,291,067 +9
android jsc x86 9,143,804 +9
android jsc x86_64 9,402,685 -4

Base commit: a2f155f
Branch: main

NickGerleman and others added 2 commits February 22, 2023 14:39
Summary:
Pull Request resolved: facebook#36236

D38198351 (facebook@d574ea3) addedd a guard to FlatList, to no-op if passed `data` that was not an array. This broke functionality where Realm had documented using `Realm.Results` with FlatList. `Real.Results` is an array-like JSI object, but not actually an array, and fails any `Array.isArray()` checks.

This change loosens the FlatList contract, to explicitly allow array-like non-array entities. The requirement align to Flow `$ArrayLike`, which allows both arrays, and objects which provide a length, indexer, and iterator.

Though `Realm.Results` has all the methods of TS `ReadonlyArray`, RN has generally assumes its array inputs will pass `Array.isArray()`. This includes any array props still being checked [via prop-types](https://github.com/facebook/prop-types/blob/044efd7a108556c7660f6b62092756666e39d74b/factoryWithTypeCheckers.js#L548).

This change intentionally does not yet change the parameter type of `getItemLayout()`, which is already too loose (allowing mutable arrays). Changing this is a breaking change, that would be disruptive to backport, so we separate it into a different commit that will be landed as part of 0.72 (see next diff in the stack).

Changelog:
[General][Changed] - Make FlatList permissive of ArrayLike data

Differential Revision: https://www.internalfb.com/diff/D43465654?entry_point=27

fbshipit-source-id: 15c9e19414b82ea8676df0428c5540097107259c
Summary:
Pull Request resolved: facebook#36237

This changes the data parameter type for `getItemLayout` from a mutable array (too lenient, even before), to `ArrayLike`, which is now the most constrained subset of data which may be passed to a FlatList.

We could do something more exact by adding another generic parameter to FlatList, but that would be likely be noticeably more breaking, since during testing I couldn't manage a pattern that both kept the same minimum number of generic arguments while keeping inference working.

Changelog:
[General][Breaking] - Constrain data type in `getItemLayout` callback

Reviewed By: javache

Differential Revision: D43466967

fbshipit-source-id: a0fa45917dfe9dcb71c543b6c86d0ce188a48c4c
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D43466967

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Feb 25, 2023
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in febf6b7.

OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
Summary:
Pull Request resolved: facebook#36237

This changes the data parameter type for `getItemLayout` from a mutable array (too lenient, even before), to `ArrayLike`, which is now the most constrained subset of data which may be passed to a FlatList.

We could do something more exact by adding another generic parameter to FlatList, but that would be likely be noticeably more breaking, since during testing I couldn't manage a pattern that both kept the same minimum number of generic arguments while keeping inference working.

Changelog:
[General][Breaking] - Constrain data type in `getItemLayout` callback

Reviewed By: javache

Differential Revision: D43466967

fbshipit-source-id: 7a1ce717e7d5cc96a58b8d3ad9def6cf6250871f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants