fix(react-virtualizer): prevent RangeError when numItems decreases while scrolled near bottom#616
Merged
dmytrokirpa merged 3 commits intomicrosoft:mainfrom Mar 3, 2026
Conversation
…ile scrolled near bottom When filtering reduces numItems while actualIndex still holds a high scroll position, renderChildRows computed a negative arrayLength causing "RangeError: Invalid array length". Clamp arrayLength to zero with Math.max(0, ...) mirroring the guard already present in updateChildArray. Also guard calculateBefore against returning a negative buffer height when numItems is 0 (static sizing path). Fixes microsoft#607 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
93cb439 to
13abf38
Compare
mainframev
approved these changes
Mar 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #607 (in microsoft/fluentui-contrib)
renderChildRows: wrapnumItems - newIndexwithMath.max(0, ...)to prevent a negativearrayLengthfrom being passed tonew Array(), which threwRangeError: Invalid array lengthwhennumItemsdecreased (e.g. filtering) whileactualIndexwas still at a high scroll position.calculateBefore: wrapMath.min(actualIndex, numItems - 1)withMath.max(0, ...)to prevent a negativebeforeBufferHeightfor static-sized lists whennumItemsdrops to0.Both fixes mirror the guard already present in
updateChildArray(Math.max(0, numItems - startIndex)).Test plan
"should not crash with RangeError when numItems decreases while scrolled near the bottom"— simulatescontextIndex = 90withnumItemsfiltered from 100 → 10, asserts noRangeErroris thrown andvirtualizedChildren.length >= 0.useVirtualizerunit tests pass (yarn jest useVirtualizer.test).🤖 Generated with Claude Code