You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The virtualizer doesn't always restore the first visible item's scroll offset after the size change. This tends to happen when the list size > 100 000 and the size change doesn't affect the currently visible items.
Expected outcome
The scroll offset should be restored after the size change.
Minimal reproducible example
it('should preserve scroll position when size decrease does not affect any rendered indexes',async()=>{// Scroll to an index and add an additional scroll offset.constindex=virtualizer.size-2000;virtualizer.scrollToIndex(index);scrollTarget.scrollTop+=10;// Decrease the size so that no rendered indexes are affected.virtualizer.size-=1000;awaitoneEvent(scrollTarget,'scroll');constitem=elementsContainer.querySelector(`#item-${index}`);expect(item.getBoundingClientRect().top).to.be.closeTo(scrollTarget.getBoundingClientRect().top-10,1);});it('should preserve scroll position on size increase',async()=>{constindex=virtualizer.size-2000;virtualizer.scrollToIndex(index);scrollTarget.scrollTop+=10;virtualizer.size+=1000;awaitoneEvent(scrollTarget,'scroll');constitem=elementsContainer.querySelector(`#item-${index}`);expect(item.getBoundingClientRect().top).to.be.closeTo(scrollTarget.getBoundingClientRect().top-10,1);});
Steps to reproduce
--
Environment
Vaadin version(s): 24.4
Browsers
No response
The text was updated successfully, but these errors were encountered:
The scroll offset appears to be reset by _adjustVirtualIndexOffset that is called on scroll event following scrollToIndex that restores the scroll position.
vursen
changed the title
[virtualizer] Does not always restore scroll offset after size change
[virtualizer] Scroll offset is not always restored after size change
Mar 19, 2024
I made an attempt to fix the issue by skipping _adjustVirtualIndexOffset in _scrollHandler if the scroll position hasn't changed since the previous scroll event. However, it revealed that the _adjustVirtualIndexOffset call – happening on scroll event that follows scrollToIndex – is important. At least, the scroll height doesn’t get always updated correctly without it. It's curious because scrollToIndex has its own logic updating _vidxOffset and I would expect no need for any further adjustments.
Besides, I noticed that scrolling to an index near the end of a large list can cause _adjustVirtualIndexOffset to be called just as many times as there are items rendered in the DOM. The reason is again scrollToIndex apparently calculating _vidxOffset inaccurately so that another adjustment is needed on the following scroll event.
Description
Follow-up to #7205
The virtualizer doesn't always restore the first visible item's scroll offset after the size change. This tends to happen when the list size > 100 000 and the size change doesn't affect the currently visible items.
Expected outcome
The scroll offset should be restored after the size change.
Minimal reproducible example
Steps to reproduce
--
Environment
Vaadin version(s): 24.4
Browsers
No response
The text was updated successfully, but these errors were encountered: