fresh icon indicating copy to clipboard operation
fresh copied to clipboard

Scroll position is not preserved when using back and forward buttons

Open lttr opened this issue 7 months ago • 2 comments

I expect to land on the same scroll position as I was before on a page A, when I use a back button on page B.

I end up on the top of the page A, instead of on the scroll position I was before.

Reproduction

  1. visit https://fresh.deno.dev/docs/getting-started/adding-interactivity
  2. scroll a little so that the link to wikipedia page "Pascal_case" is on the top
  3. click on the link, I am now on page https://en.wiktionary.org/wiki/Pascal_case
  4. hit Back button in the browser
  5. I can see the heading "Adding interactivity", which was not the case after step 2. and is unexpected

Expected behavior

Ideally the scroll position would be preserved at the exact same position, as it is done on plain HTML by browsers.

Notes

  • The scroll position IS preserved, when I'm using internal links after hitting the Back button.
  • The scroll position IS NOT preserved, when I'm using iternal links after hitting Back button and than hitting Forward button. I end up on the top of the page, even though I have scrolled down before navigation.
  • Preserving scroll position seems to be hard or not understood, since earlier versions of multiple other frameworks had a similar issue

Environment

Browser: Firefox 118 OS: Pop_OS (Ubuntu) 22.04

lttr avatar Nov 06 '23 04:11 lttr

This may have been fixed meanwhile. It appears not to happen anymore, at least in Firefox (119) and Safari (17.1):

https://github.com/denoland/fresh/assets/7757/0b8ee070-133a-43b7-bfd5-e42f5a793293

bastilian avatar Nov 19 '23 21:11 bastilian

I did also try to manually go to the link, without using the internal link, and enter it manually into the address bar, which also properly preserved the scroll position when going back and forward.

bastilian avatar Nov 19 '23 21:11 bastilian