Upon going back to the feed page from a post page, the feed tends to load in at a different point (higher up) than where it was before. This results in a lot of repetitive scrolling.

Also, I noticed that (when new content is being loaded in?) the scrolling gets stuck in the same spot. Scrolling kind of just glitches on the same spot until it gets past it and then resumes as normal.

  • moseschrute@lemmy.world
    link
    fedilink
    English
    arrow-up
    4
    ·
    8 days ago

    I don’t use Photon, but I glanced at the source code and it looks like they are also using Tanstack Virtual, which my Lemmy client uses. My app is in beta an doesn’t have many users, but I think I solved this feed issue.

    You need to do a few things:

    1. On scroll, save the first item being rendered in the virtual list + the offset of that item from the top (offset can be negative or positive)
    2. Pause the virtualization when the list is no longer visible (use IntersectionObserver)
    3. When the user returns to the list, reenable virtualization while simultaneously recalculating initalOffset to be passed to the virtual list.

    You have to recalculate initalOffset when returning to the list, NOT when you are scrolling through the list. If you try to calculate it while scrolling the feed, you will drift a few posts upwards/downwards. Using initial item + offset yields a much more stable result.

    It’s all pretty messy, but take a look at my spaghetti code.

  • Xylight@lemdro.idM
    link
    fedilink
    English
    arrow-up
    1
    ·
    8 days ago

    I’m definitely gonna have to write my own virtualizer. I tried using Tanstack Virtual but it definitely has too many issues with my setup to work well.

      • Xylight@lemdro.idM
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        7 days ago

        I did. In the long run it’s better for me to write my own since it’s easier to update and debug

        • technomad@slrpnk.netOP
          link
          fedilink
          English
          arrow-up
          1
          ·
          4 days ago

          I just wanted to say thanks for the reply btw. I look forward to seeing the updates whenever they may come, and I appreciate what you do!