uni-virtualizer icon indicating copy to clipboard operation
uni-virtualizer copied to clipboard

`_getAnchor: negative _first` when calling scrollToIndex

Open jpzwarte opened this issue 2 years ago • 4 comments

I'm working on a combo-box component. The overlay contains a <lit-virtualizer> element with the list. When I open the overlay and there is a selected item, I scroll the virtualizer to that item (centered) using virtualizer.scrollToIndex(selectedIndex, 'center');

Now if I do this, before the overlay is visible, I get the _getAnchor: negative _first message in the console and it scrolls to the incorrect location. When I do this after the overlay is visible, it scrolls to the correct item in the list, but it "jumps": the original position of the list is briefly visible. See the video below.

https://user-images.githubusercontent.com/3968/169555089-7e26f755-6209-4db4-859b-88e1afaceb5d.mov

jpzwarte avatar May 20 '22 14:05 jpzwarte

Thanks for the bug report, @jpzwarte. I don't suppose you have a repro case we can run? A minimal repro in the Lit Playground would be ideal, but anything is better than nothing.

We've recently been working on a pretty thorough overhaul of virtualizer's "scroll-to" functionality, including a way to declaratively specify the scroll position on the initial render. I think this should meet your needs, but I'd like to make sure these issues in the imperative case are handled as well.

graynorton avatar May 20 '22 15:05 graynorton

Sounds good! I need to debug the situation a bit more. Seeing some other weird stuff that I'm not sure is not related to the way I provide the items to the virtualizer. (I'm using the VirtualArray technique from the examples to do something similar).

jpzwarte avatar May 20 '22 16:05 jpzwarte

@graynorton affaict, what happens is that when calling scrollToIndex() before the overlay is shown: Screenshot 2022-05-23 at 10 26 43

The first _first is 0 is from before I triggered opening the overlay.

  • _first is XX is a logpoint in flow.ts on line 373
  • scrollToIndex is XX is a logpoint in flow.ts on line 312
  • _scrollPositionChanged is a logpoint in BaseLayout.ts on line 508
  • the error message is flow.ts line 236

jpzwarte avatar May 23 '22 08:05 jpzwarte

@jpzwarte did you find a solution for this issue?

joekukish avatar Jun 25 '22 15:06 joekukish