Repository navigation
fix: seed horizontal window virtualizers from window.scrollX #1383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| '@tanstack/react-virtual': patch | ||
| '@tanstack/vue-virtual': patch | ||
| '@tanstack/svelte-virtual': patch | ||
| '@tanstack/solid-virtual': patch | ||
| '@tanstack/lit-virtual': patch | ||
| '@tanstack/angular-virtual': patch | ||
| --- | ||
|
|
||
| Seed a horizontal window virtualizer's default `initialOffset` from `window.scrollX` instead of `window.scrollY`, matching `observeWindowOffset` and the Marko adapter. A horizontal list mounted on a page that was scrolled down no longer renders the columns at the vertical scroll position until the first scroll event. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -314,7 +314,12 @@ export function useWindowVirtualizer<TItemElement extends Element>( | |
| observeElementRect: observeWindowRect, | ||
| observeElementOffset: observeWindowOffset, | ||
| scrollToFn: windowScroll, | ||
| initialOffset: () => (typeof document !== 'undefined' ? window.scrollY : 0), | ||
| initialOffset: () => | ||
| typeof document !== 'undefined' | ||
| ? options.horizontal | ||
| ? window.scrollX | ||
|
Comment on lines
+318
to
+320
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| : window.scrollY | ||
| : 0, | ||
| ...options, | ||
| }) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,7 +103,12 @@ export function createWindowVirtualizer<TItemElement extends Element>( | |
| observeElementRect: observeWindowRect, | ||
| observeElementOffset: observeWindowOffset, | ||
| scrollToFn: windowScroll, | ||
| initialOffset: () => (typeof document !== 'undefined' ? window.scrollY : 0), | ||
| initialOffset: () => | ||
| typeof document !== 'undefined' | ||
| ? options.horizontal | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Read the current axis when initializing the offset. The callback captures the original Make the default callback read the virtualizer’s current axis.
|
||
| ? window.scrollX | ||
| : window.scrollY | ||
| : 0, | ||
| ...options, | ||
| }) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Read the current axis when initializing the offset.
The callback captures the constructor’s
options, butsetOptionsreplaces the controller’s stored options. If a controller starts withhorizontal: trueandenabled: false, then is enabled withhorizontal: false, it readsscrollXinstead ofscrollY. Core then writes that value to the vertical window position, which can move the page. (raw.githubusercontent.com)Make the default callback read the virtualizer’s current axis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right: in the Lit and Svelte adapters this default is created once, so it keeps reading the axis the virtualizer was created with. Core only reads
initialOffsetwhilescrollOffsetis unset (on first use, and again after the virtualizer has been disabled), so this shows up whenhorizontalchanges throughsetOptionsand the offset is then re-initialized, for example disabled and re-enabled on the other axis.Core passes the instance to
scrollToFn,observeElementRect,observeElementOffsetandmeasureElement, but not toinitialOffset, so these two adapters can't read the live option without a core change. If you'd like, I can make core callinitialOffset(this)and have each window adapter readinstance.options.horizontal, either here or in a follow-up.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Analysis chain
Script executed:
Length of output: 21939
@Ishkirat-SinghThanks for tracing this. Please fix it in this PR: the change can introduce a wrong offset when a controller switches from horizontal to vertical.Passing the instance to
initialOffsetis a reasonable approach, but it changes the public core API. An adapter-only fix may be smaller: refresh the default callback when options change, while preserving any user-providedinitialOffset.Please add Lit and Svelte regression tests that reset the offset while disabled, change the axis, and re-enable the virtualizer. Also test explicit
initialOffsetoverrides. If you change core, please check compatibility with existing zero-argument callbacks and direct callers.You are interacting with an AI system.