[BUG] Wrong startIndex and endIndex rangeChanged callback in GroupedVirtuoso component
See original GitHub issueDescribe the bug
Using GroupedVirtuoso with rangeChanged callback, the range startIndex and endIndex returned by the function sometimes emit wrong values.
i have this summarized implementation:
<GroupedVirtuoso
data={users}
style={{ height: 200 }}
groupCounts={[500, 500]}
rangeChanged={(range) => console.log(range)}
ref={virtuoso}
itemContent={(index, _, user) => {
return (
<div {...item} />
);
}}
/>
Reproduction https://codesandbox.io/s/sandpack-project-forked-i1hkpv?file=/App.js
To Reproduce Steps to reproduce the behavior:
- Click on ‘Scroll to 500’
- See the log of the rangeChanged callback
- If everything is normal, then scroll the list up and down
Expected behavior
I think the expected behavior is the rangeChanged emit only indexes that the list is rendering on the screen. And the startIndex cannot be greater than endIndex.
For example, in the image below:
- First log: The
startIndex: 497andendIndex: 1should never happens because itendIndexcannot be smaller thanstartIndex - Last log: The
startIndex: 1andendIndex: 502should not be printed because all of this items list is not being rendered at this time.
Screenshots

Desktop (please complete the following information):
- OS: Ubuntu Linux
- Browser: Chrome
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Using overscan leads to incorrect rangeChanged indices #118
I'd expect them to still only include the visible content (as I'd like to use this callback to determine what's actually visible).
Read more >Range Change Callback | React Virtuoso
The rangeChanged callback property gets called with the start/end indexes of the visible range. Note: the rangeChanged reports the rendered items, ...
Read more >react-virtuoso: Versions - Openbase
A change which makes the component CSP compliant (#77); Port of rangeChanged to the GroupedVirtuoso component variant. (#81) ...
Read more >Support for sticky items,about petyosi/react-virtuoso - GithubHelp
Just published v0.3.0 that includes a GroupedVirtuoso component that supports sticky group ... [BUG] Wrong startIndex and endIndex rangeChanged callback in ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Great. Fork the repo, push your branch there, and GH should suggest the way: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork
Confirming that, it’s a weird bug. I will look into it.