`useVirtualizer({paddingEnd: 800})` creates overscroll issue with `scrollToIndex(last)`
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 68/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- react, typescript
- 领域
- frontend
调研方向
从链接的最小复现开始,跟踪 useVirtualizer 和 scrollToIndex 的入口点,重点关注 paddingEnd 和 last-index 的行为。使用提供的按钮复现该问题,然后验证滚动到最后一个索引时,项目会保持完全可见,同时不会使容器过度滚动。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
The paddingEnd option for the useVirtualizer callback is not correctly taken into account when using rowVirtualizer .scrollToIndex(last). Instead the function call scrolls to the end of the scroll container. For every other index this works as intended.
const rowVirtualizer = useVirtualizer({
count: 100,
getScrollElement: () => parentRef.current,
estimateSize: () => 35,
overscan: 5,
paddingEnd: 800
})
// ...
<button onClick={() => {
rowVirtualizer.scrollToIndex(98)
}}>
Scroll to 98 (works)
</button>
<button onClick={() => {
rowVirtualizer.scrollToIndex(99)
}}>
Scroll to 99 (overscrolls)
</button>
Your minimal, reproducible example
https://github.com/Freymaurer/tanstack-virtual-padding-overscroll-bug-example
Steps to reproduce
- Clone and
npm i->npm run devthe example (fresh vite-react-ts with tanstack virtual dependency) -> open the link printed to console - Click the buttons i added on top of the view
- "Back to Start" uses
scrollToIndex(0) - "Scroll to 98 (works)" scrolls to 98, so not last index
- "Scroll to 99 (overscrolls)" scrolls to the last index
- Click on "Back to Start", then "Scroll to 98 (works)". It scrolls with pretty good alignment. The field is shown on the bottom of the scrollContainer
- Click on "Back to Start", then "Scroll to 99 (overscrolls)". It overscrolls, the element is not visible on screen. 🐛 I think this is due the library calling more or less "scrollToEnd" instead of "scrollTo" in this scenario.
Expected behavior
I expected the behavior to be consistent. The element at last index should be fully visible after calling the scroll function, instead of scrolling to the scroll container end
How often does this bug happen?
Every time
Screenshots or Videos
After clicking on "Scroll to 98 (works)"
After clicking on "Scroll to 99 (overscrolls)"
Platform
OS: Windows 11
Browser: Tested on Chrome, Edge, Firefox, Opera
tanstack-virtual version
v3.14.9
TypeScript version
v6.0.3
Additional context
No response
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
- 主要语言
- TypeScript
- 星标
- 7.1k
- 派生
- 466
- 平均合并
- 2 天 31 分钟
- 30 天内合并 PR
- 13
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/virtual 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 55/100
-
难度 5/5 一周以上 新手友好度 38/100
-
难度 4/5 3-5 天 新手友好度 62/100
-
难度 4/5 3-5 天 新手友好度 55/100
-
难度 4/5 3-5 天 新手友好度 42/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
mksglu/context-mode#1200 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
jaegertracing/jaeger-ui#4506 ·
-
area:desktop area:ui bug platform:macos
难度 2/5 1-3 小时 新手友好度 75/100
anthropics/claude-code#96687 ·
-
good first issue
难度 1/5 1 小时以内 新手友好度 95/100
AOSSIE-Org/DebateAI#582 · 2 条评论 ·