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:
- 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)
- Pause the virtualization when the list is no longer visible (use IntersectionObserver)
- 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.