useWindowVirtualizer with measureElement breaks scroll restoration
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- react, typescript
- Lĩnh vực
- frontend, performance
Hướng nghiên cứu
Chạy bản tái hiện trên CodeSandbox và so sánh việc điều hướng khi có và không có tùy chọn scrollToFn được comment. Theo dõi tương tác giữa useWindowVirtualizer, measureElement, việc đo lại và khôi phục vị trí cuộn trong các bước điều hướng được liệt kê; hoàn tất khi danh sách quay lại đầu mà không cần workaround.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
When using
"@tanstack/react-virtual": "3.13.8"
and
"@tanstack/react-router": "1.112.12"
If the page contains a virtualized list like this:
const virtualizer = useWindowVirtualizer({
gap: 16,
overscan: 4,
count: data.items.length,
estimateSize: constant(188),
scrollMargin: listRef.current?.offsetTop ?? 0,
});
And the items use:
ref={virtualizer.measureElement}
data-index={index}
But the actual element sizes differ from estimateSize, triggering re-measurement on mount — in that case, scrollRestoration breaks.
This might be an issue on the @tanstack/react-router side; I’ll duplicate this issue there as well.
Current workaround: add this option to the virtualizer:
scrollToFn: () => null,
Your minimal, reproducible example
https://codesandbox.io/p/sandbox/2lryyk
Steps to reproduce
1 Open the Home page
2 Scroll down a bit
3 Navigate to the List page
4 You'll notice that the page is not scrolled to the top
In the code, there's a commented line:
in code there are commented string with
scrollToFn: () => null
Uncommenting this line.
After doing that, navigation with scroll restoration works perfectly.
Expected behavior
Virtualizer does not break scroll restoration.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
maxOS
tanstack-virtual version
3.13.8
TypeScript version
5.7.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.
- Ngôn ngữ chính
- TypeScript
- Star
- 7.1k
- Fork
- 468
- Merge trung bình
- 1 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 12
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/virtual
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 38/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của TanStack/virtual
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
melgarafael/DeskcommCRM#1812 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
prisma/prisma-cli#309 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
gregwebs/pi-quota-dispatcher#26 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
openwatersio/slackwater.xyz#124 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent-reported area/browser area/docs documentation good first issue hacktoberfest help wanted P2
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
Maintainer thường phản hồi trong vòng 2 ngày