Skip to content
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

Cannot scroll up in vue dynamic example #619

Open
2 tasks done
ghost opened this issue Nov 3, 2023 · 6 comments
Open
2 tasks done

Cannot scroll up in vue dynamic example #619

ghost opened this issue Nov 3, 2023 · 6 comments

Comments

@ghost
Copy link

ghost commented Nov 3, 2023

Describe the bug

Cannot scroll up in vue dynamic example

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/github/tanstack/virtual/tree/beta/examples/vue/dynamic?embed=1

Steps to reproduce

  1. Scroll down
  2. Try to scroll up

Expected behavior

I expect that it will scroll up without lag

How often does this bug happen?

Every time

Screenshots or Videos

Screen.Recording.2023-11-04.at.02.12.57.mp4

Platform

OS - MacOS Sonoma, Windows, Linux
Browser - Chrome Version 118.0.5993.117 (Official Build) (arm64). This issue works only in chromium browsers

tanstack-virtual version

See in codesandbox (ノ>_<)ノ

TypeScript version

No response

Additional context

No response

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • 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.
@ssp7
Copy link

ssp7 commented Dec 28, 2023

Any update on this?

@KevinVandy
Copy link
Member

Any update on this?

Are you using Vue or React?

@ssp7
Copy link

ssp7 commented Dec 28, 2023

Any update on this?

Are you using Vue or React?

React

@nconfrey
Copy link

nconfrey commented Feb 1, 2024

I fixed a similar problem by modifying the Virtualizer to not remeasure elements when scrolling up:

measureElement: (element, entry, instance) => {
      const direction = instance.scrollDirection
      if (direction === "forward" || direction === null) {
        return element.scrollHeight
      } else {
        // don't remeasure if we are scrolling up
        const indexKey = Number(element.getAttribute("data-index"))
        let cacheMeasurement = instance.itemSizeCache.get(indexKey)
        return cacheMeasurement
      }
    }

@BazanAlexandro
Copy link

BazanAlexandro commented Feb 28, 2024

Was able to fix this by delaying measurements with nextTick before measureElement. Looks like vue renders items a bit later, breaking dynamic measurements.

So, my measure function looks like this

  const measureElement = (el: any) => {
    nextTick(() => {
      if (!el) return;
      rowVirtualizer.value.measureElement(el);
    });
  };

@AlejandroAkbal
Copy link

Thanks @BazanAlexandro, your solution works perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants