Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

useWindowVirtualizer with measureElement breaks scroll restoration

Đang mở
#997 4 bình luận 2 reaction 0 người được giao Xem trên GitHub

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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/virtual

Tất cả issue của TanStack/virtual

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.