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

Avoid VirtualizedList viewability updates during state updates #36340

Closed
wants to merge 1 commit into from

Conversation

NickGerleman
Copy link
Contributor

Summary:
VirtualizedList refactoring moved a call of _updateViewableItems to the inside of a state update.

This call may trigger an onViewableItemsChanged, which is normally not an issue (minus changing timing), but creates problems if the users callback then calls imperative methods on the VirtualizedList, since the batched state update may be in the process of changing the props/state the imperative method is reading. See #36329 for what I suspect is an example of this.

This moves the _updateViewableItems call to before the state update, like the previous version of VirtualizedList.

Changelog:
[General][Fixed] - Avoid VirtualizedList viewability updates during state updates

Reviewed By: javache

Differential Revision: D43665606

Summary:
VirtualizedList refactoring moved [a call of `_updateViewableItems`](https://www.internalfb.com/code/fbsource/[a9d4ad3cf149][history][blame]/xplat/js/react-native-github/Libraries/Lists/VirtualizedList.js?lines=1431-1447) to the inside of a state update.

This call may trigger an `onViewableItemsChanged`, which is normally not an issue (minus changing timing), but creates problems if the users callback then calls imperative methods on the VirtualizedList, since the batched state update may be in the process of changing the props/state the imperative method is reading. See facebook#36329 for what I suspect is an example of this.

This moves the `_updateViewableItems` call to before the state update, like the previous version of VirtualizedList.

Changelog:
[General][Fixed] -  Avoid VirtualizedList viewability updates during state updates

Reviewed By: javache

Differential Revision: D43665606

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

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

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,477,095 +56
android hermes armeabi-v7a 7,799,079 +60
android hermes x86 8,953,089 +60
android hermes x86_64 8,810,587 +53
android jsc arm64-v8a 9,108,176 -11
android jsc armeabi-v7a 8,304,844 -10
android jsc x86 9,159,032 -9
android jsc x86_64 9,418,319 +0

Base commit: f23f7f4
Branch: main

@NickGerleman
Copy link
Contributor Author

Commited with 62a0640

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

Successfully merging this pull request may close these issues.

4 participants