Repository navigation
Replies: 2 comments 1 reply
|
This looks like a Headless UI bug rather than an In the current implementation, A library-side fix should separate element attachment from scrolling:
Simply memoizing the existing callback without handling active-index changes could break keyboard navigation to offscreen options. The public React's callback-ref behavior is documented here, and TanStack Virtual's |
|
Most of this is fixed by updating npm update @tanstack/react-virtual
npm ls @tanstack/virtual-core # needs 3.13.21 or laterThe multi-step drift went away in
One step is left, and that part is Headless UI. I logged the virtualizer inside the inline ref: the first If you need that gone too, give the list a definite height instead of <ComboboxOptions style={{ height: 300, overflow: 'auto', width: 220, border: '1px solid #999' }}>With 3.14.14, your 19px rows and |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
What package within Headless UI are you using?
@headlessui/react
What version of that package are you using?
2.2.9 (the relevant code in 2.2.10 looks the same: VirtualProvider still calls scrollToIndex(activeOptionIndex) from an inline ref callback)
What browser are you using?
Firefox (desktop), Chromium (Playwright 1.58.1)
Other versions: React 19.2.4, @tanstack/react-virtual 3.13.18
Reproduction
Any option styling works; with .option { padding: 2px 4px } a row is ~19px tall.
Steps
Expected
The list opens scrolled to the selected option once, without visible movement.
Actual
On every reopen, the list visibly jumps several times over the first few frames before it settles. Logging optionsElement.scrollTop on each animation frame after opening gives the same sequence every time:
15492 → 15475 → 15181 → 14898 → 14877
The final position is correct (Option 401 is visible), but the intermediate jumps are visible as a flicker at the top of the list.
For an option near the top (Option 10) the sequence is shorter but still visible: 196 → 180 → 0.
The first open, with no value selected, does not jump.
Notes
This is the documented virtual scrolling setup (virtual.options plus a render prop for ComboboxOptions). No extra wrappers, static or custom refs.
It is not caused by the row height differing from the 40px estimateSize. With options forced to exactly height: 40px the list still jumps (438 → 400 → 138 for Option 10, 16078 → 16040 → 15778 for Option 401).
It looks like VirtualProvider calls virtualizer.scrollToIndex(activeOptionIndex) from an inline ref callback, so it runs again on every re-render while the options mount, measure, and read scrollPaddingStart/End. Each call scrolls to a slightly different position.
Possibly related, but a different scenario: #3189 (fixed in #3190, native scrollbar jitter in an already open list).
virtual only accepts options and disabled, so there is no documented way to control this from the outside.
All reactions