Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`useVirtualizer({paddingEnd: 800})` creates overscroll issue with `scrollToIndex(last)`

未关闭
#1,257 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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
  1. Clone and npm i -> npm run dev the example (fresh vite-react-ts with tanstack virtual dependency) -> open the link printed to console
  2. 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
  1. 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
  2. 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)"

Image

After clicking on "Scroll to 99 (overscrolls)"

Image
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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/virtual 的其他 Issue

查看 TanStack/virtual 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。