virtual icon indicating copy to clipboard operation
virtual copied to clipboard

[VR] Scrolling to index is incorrectly align for first effect in dynamic mode

Open piecyk opened this issue 2 years ago • 1 comments

Describe the bug

When calling scrolling to index in initial render the item is not correctly align,

React.useEffect(() => {
  virtualizer.scrollToIndex(500)
}, [virtualizer])

it happens because in dynamic mode position of item can change while elements are mounted. To fix this, we are checking in next tick if the position changed. Overall this should be only enabled for dynamic case, via isDynamicMode condition https://github.com/TanStack/virtual/blob/beta/packages/virtual-core/src/index.ts#L826 and there we only check if we have rendered elements.

This was working as side effect of rendering rows even when we should not, noticed after #603.

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/recursing-kowalevski-dfl62x

Steps to reproduce

No action required.

Expected behavior

Item is correctly align.

How often does this bug happen?

Every time

Screenshots or Videos

.

Platform

macOS, Chrome

tanstack-virtual version

v3.0.0-beta.68

TypeScript version

No response

Additional context

Current workaround wound be to wrap the scrollToIndex with setTimeout

React.useEffect(() => {
  setTimeout(() => {
    virtualizer.scrollToIndex(500)
  }, 0)
}, [virtualizer])

Terms & Code of Conduct

  • [X] I agree to follow this project's Code of Conduct
  • [X] I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

piecyk avatar Oct 23 '23 10:10 piecyk

Hi, is there any estimate on when the issue will be resolved?

mariia-mitiureva avatar Nov 10 '23 16:11 mariia-mitiureva