When using useWindowVirtualizer across multiple screens, the scroll position is carried over. Is there a way to reset it? #739
Replies: 4 comments
-
memo:
|
Beta Was this translation helpful? Give feedback.
-
Although I haven't fully traced the code yet, I have found the following points:
However, I find the functionality of adjusting the scroll position during resizing to be very useful. From my debugging, I have determined that the root cause is that this.scrollOffset or this.scrollAdjustments retains the previous values. I will continue reading the code to further investigate this issue. |
Beta Was this translation helpful? Give feedback.
-
[Update] I believe this can be addressed by custom controlling the timing of the observeElementOffset trigger. |
Beta Was this translation helpful? Give feedback.
-
@shunshimono did you manage to fix this in your code? I am facing the same issue and nothing works properly. Sometimes |
Beta Was this translation helpful? Give feedback.
-
Hello,
In my project, I am using Next.js and @tanstack/react-virtual. When using useWindowVirtualizer across multiple screens, the scroll position from the previous screen is automatically restored.
Reproducible Environment
CodeSandbox Example
Reproduction Steps
Scroll on localhost:3000
Navigate to the ABOUT PAGE
Expected Behavior
The scroll position should start from the top.
Things I Tried but Didn't Work
Executing the measure method and initializing the cache on unmount: measure method
Setting initialOffset to 0: initialOffset
Setting scrollToOffset to 0 on mount: scrollToOffset
Additional Observations
If I don't use measureElement, this issue doesn't occur.
I hypothesize that this is caused by the cache of measureElement being shared across screens. If anyone knows a solution, I would appreciate your support.
Thank you for reading.
Beta Was this translation helpful? Give feedback.
All reactions