beacon icon indicating copy to clipboard operation
beacon copied to clipboard

Preserve scroll position

Open bcardarella opened this issue 2 years ago • 3 comments

This is a problem in LiveView but we can solve it on our own. Pages currently don't preserve scroll position. See:

https://user-images.githubusercontent.com/18524/215903473-99d47362-fac5-495d-b7ad-3071c45a5b61.mp4

I solved this a few years ago in ember-router-scroll: https://github.com/DockYard/ember-router-scroll/blob/master/addon/services/router-scroll.js

We'll need to pull in some JS resources to implement in Beacon. Two cases need to be accounted for:

  1. preserving scroll position when navigating to a new page then back to the original
  2. preserving scroll position when reloading a page (hard refresh also respects position)
  3. if opening a new tab to the same URL or navigating forward from A, to B, and pushing a new instance of A to the history stack it shouldn't inherit the scroll position of the original visit of A but if I go back in history it should

bcardarella avatar Jan 31 '23 23:01 bcardarella

For reference there're currently 2 open issues upstream related to scroll: https://github.com/phoenixframework/phoenix_live_view/issues/2326 and https://github.com/phoenixframework/phoenix_live_view/issues/2107

leandrocp avatar May 02 '23 16:05 leandrocp

This being solved at the Phoenix level instead of at the Beacon level would be amazing!

zolrath avatar May 10 '23 20:05 zolrath

I agree, that's something we'll need to solve eventually. Fixing it upstream makes sense.

leandrocp avatar May 10 '23 20:05 leandrocp