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

refine invariant error message at scrollToIndex #28464

Conversation

sasurau4
Copy link
Contributor

@sasurau4 sasurau4 commented Mar 31, 2020

Summary

I refined the error message of scrollToIndex.

When I used scrollToIndex with index:0 and data that length is 0, I met the odd error message Invariant Violation scrollToIndex out of range: requested index 0 but maximum is -1.

Next, I thought that scrollToIndex with index:-1 meant scrollToTop without checking data length. I met Invariant Violation: scrollToIndex out of range: requested index -1 but maximum is -1

Finally, I wondered what will happen to use scrollToIndex with index:-1 and data that length is 5. The result is Invariant Violation: scrollToIndex out of range: requested index -1 but maximum is 5

The above error messages will confuse us. I clarified the boudaries and separated the error messages

Changelog

[General] [Fixed] - Clarified the boundaries in error message of scrollToIndex

Test Plan

I added 3 test cases to cover the new error messages for VirtualizedList.
Run yarn test and confirm it passes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 31, 2020
@analysis-bot
Copy link

analysis-bot commented Mar 31, 2020

Platform Engine Arch Size (bytes) Diff
ios - universal 10,903,792 243,728

Base commit: 90f60a8

@elicwhite
Copy link
Member

Your test plan says not needed, tests must pass, does that mean there are tests for this? If so, since you are adding error messages and trusting tests, I'd expect to see additional tests covering this new behavior.

@sasurau4
Copy link
Contributor Author

sasurau4 commented Apr 5, 2020

@TheSavior Thanks for pointing out 👍 I added test cases.

@analysis-bot
Copy link

analysis-bot commented Apr 5, 2020

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 6,758,892 -599
android hermes armeabi-v7a 6,405,934 -602
android hermes x86 7,140,312 -578
android hermes x86_64 7,031,618 -603
android jsc arm64-v8a 8,927,824 -217
android jsc armeabi-v7a 8,567,266 -215
android jsc x86 8,752,361 -224
android jsc x86_64 9,329,309 -210

Base commit: 90f60a8

);
});

it('throws if using scrollToIndex when requested index is bigger than or equal to item length', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one I’m not sure about. With VirtualizedList you can do tail loading. So when you scroll to the bottom of the list you can fetch more data and render it. If scrollToIndex is greater than the data length I’d expect fail loading to be possible and for it to continue trying to scroll to the index. I’m not sure what the current behavior is but I’m a bit concerned about throwing in this case.

Can you either remove this condition or do a bit more investigation into that edge case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remove this condition.

@sasurau4 sasurau4 force-pushed the fix/better-error-message-at-scrollToIndex branch from 88b2663 to 09c4363 Compare April 15, 2020 14:11
@sasurau4 sasurau4 force-pushed the fix/better-error-message-at-scrollToIndex branch from 09c4363 to a39197d Compare April 15, 2020 14:18
@sasurau4 sasurau4 requested a review from elicwhite April 15, 2020 14:19
@elicwhite
Copy link
Member

I'm so sorry. I missed that the original code had invariant(index < getItemCount(data). I didn't see that until now. The original condition I asked you to remove seems like it was consistent with the original behavior. Can you add it back? 😓

This reverts commit f898b30.
@sasurau4
Copy link
Contributor Author

I revert the f898b30 👍

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheSavior has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @sasurau4 in 78d2b3c.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Apr 29, 2020
@sasurau4 sasurau4 deleted the fix/better-error-message-at-scrollToIndex branch April 29, 2020 11:53
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. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants