fresh
fresh copied to clipboard
Scroll position is not preserved when using back and forward buttons
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
- visit https://fresh.deno.dev/docs/getting-started/adding-interactivity
- scroll a little so that the link to wikipedia page "Pascal_case" is on the top
- click on the link, I am now on page https://en.wiktionary.org/wiki/Pascal_case
- hit Back button in the browser
- 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
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
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.