bvaughn / react-window

React components for efficiently rendering large lists and tabular data
https://react-window.now.sh/
MIT License
15.82k stars 785 forks source link

Bug: FixedSizeList scrollToItem "center" strategy sometimes scrolls item out of view #702

Closed chuckdries closed 1 month ago

chuckdries commented 1 year ago

Certain combinations of height, itemSize, and itemCount parameters can cause the "center" mode of scrollToItem to behave incorrectly. In this example sandbox, clicking the "scroll to 41" button consistently scrolls item 41 out of view (tested in chrome)

https://codesandbox.io/s/react-window-center-scroll-bug-29r22j?file=/src/App.tsx

We appear to be hitting this case when we shouldn't be: https://github.com/bvaughn/react-window/blob/51ec3f896e7501acd6f399c759047781112fadf0/src/FixedSizeList.js#L69

though I don't understand that function well enough to see exactly where it's going wrong.

134355 commented 1 year ago

There is a problem with the height setting