-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
refine invariant error message at scrollToIndex #28464
Conversation
Base commit: 90f60a8 |
Your test plan says |
…tter-error-message-at-scrollToIndex
@TheSavior Thanks for pointing out 👍 I added test cases. |
Base commit: 90f60a8 |
); | ||
}); | ||
|
||
it('throws if using scrollToIndex when requested index is bigger than or equal to item length', () => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remove this condition.
88b2663
to
09c4363
Compare
…tter-error-message-at-scrollToIndex
09c4363
to
a39197d
Compare
I'm so sorry. I missed that the original code had |
This reverts commit f898b30.
I revert the f898b30 👍 |
There was a problem hiding this 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.
This pull request was successfully merged by @sasurau4 in 78d2b3c. When will my fix make it into a release? | Upcoming Releases |
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 messageInvariant 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 metInvariant 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 is5
. The result isInvariant 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.