useWindowVirtualizer with measureElement breaks scroll restoration
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- react, typescript
- 領域
- frontend, performance
調査の方向性
CodeSandbox の再現手順を実行し、コメントアウトされた scrollToFn オプションがある場合とない場合でナビゲーションを比較します。記載されたナビゲーション手順の実行中に、useWindowVirtualizer、measureElement、再測定、スクロール復元の間の相互作用を追跡します。リストが workaround を必要とせずに先頭へ戻れば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- TypeScript
- スター
- 7.1k
- フォーク
- 468
- 平均マージ
- 1日 2時間
- マージ済み PR(30日)
- 12
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/virtual のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
メンテナーはふだん 1 日以内に返信
TanStack/virtual の issue をすべて見る
似ている issue
-
triage
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
mermaid-js/mermaid-live-editor#2053 ·
メンテナーはふだん 1 日以内に返信
-
factory
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
jessepollak/home#1455 ·
メンテナーはふだん 1 日以内に返信
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
lingdojo/kana-dojo#31227 · コメント 1 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
appandflow/stim#1838 ·
メンテナーはふだん 1 日以内に返信