-
-
Notifications
You must be signed in to change notification settings - Fork 428
Anchor linking and scroll position after refresh not working #784
Comments
Same here, keeping the scroll position when refreshig a page is very important in a website. When changing route then going back to previous route with browser back button, the scroll position is correctly kept. How can we keep scroll position when refreshing ? |
Just realised this is still an issue - anchor links just don't work as part of an "a" tag. From a "refresh" point of view, it's clear - Sapper stores the It would be good to understand the technical reasons why this doesn't work if you click an 'a' tag on a different page though. My content is very much static, stored inside a How do other frameworks handle this? Nuxt? Next? |
Thanks for the info. Is there an easy way to store the scroll position in local storage for example, or anywhere it wouldn't reset at refresh ? |
Since Sapper is essentially serving an SPA, a refresh is "out of bounds" for its concern. The only reason a user should be refreshing is if the application broke or similar, so I can't see this scenario being handled/being a concern of Sapper. |
In my point of vue (maybe it won't be accurate as I'm relatively new to modern javascript and frameworks), Svelte is serving SPA and Sapper is here to handle SEO and multiples routes, which is required for websites. When I'm on a website, I quite often refresh the page when a lazy loaded image fails to appear for example. Going back to top when refreshing a page in a website is bad in a UX perspective. So I would argue it should be a concern for Sapper, as it was for Nuxt which handles scroll position correctly 😉 To sum up, if I wanted to make an app, I would use Svelte and wouldn't care about scroll position. |
Thanks for the info @antony . I get what you're saying, but let's say I'm building a large site for a newspaper with a cms. There will be hundreds of articles and maybe I leave a bit of leeway for the editors to do some creative stuff, like allowing canvas elements where they could hire a creative developer to build something. It could then be that this developer forgot to listen for window resize to update the content of the webgl canvas and now the page looks weird for the user, which is why a refresh would fix it. Though we strive for perfection, the story above is quite common down the road of any live project. Simply put, the regular web allows for refresh without scrolling to the top, so so should our pages, I think :) |
Still no news about that 😢. Session or Local Storage could help with scroll position. Here is a temporary fix someone used when Nuxt wasn't saving scroll position, maybe it could work in Sapper too:
|
This comment has been minimized.
This comment has been minimized.
for anyone reading, the anchor tag issue is actually a different issue because sapper sets the baseurl tag. search this repo for baseurl related issues |
When designing a website, everytime I make changes to CSS the whole website resets and scrolls to the top. This is such a bummer during development, breaks the flow of UI dev. This is also such a bummer for static sites generated using sapper, scroll position has to be saved / there should be an option to enable that. |
This should be fixed now in 0.27.13. |
Doesn’t work in Safari for some reason (tried on Safari 13.1 for macOS Catalina). |
@Conduitry it also doesn't work for me (tried in Chrome 83 and Safari 13.5) when using normal @marcfilleul i tried your code in |
@niklasgrewe this issue is about anchor tag targets. E.g. you can click https://sapper.svelte.dev/docs#Error_page and it will take you down the page to the appropriate section |
@benmccann oh sorry, ok all right. Then should I create a new issue in this repo for my case (restore scroll position) or is there already a issue for this case? |
Currently it seems the natural Sapper behaviour when you refresh a page is to jump to the top. I'm guessing this is because the dom doesn't exist initially so there is no dom to be scrolled down to.
Even more so I'm concerned this impacts direct linking to anchor links on a page as they neither seem to work naturally. I could check the url hash and do the scroll in code, but I'm concerned it might still hurt SEO score.
To replicate the issue, simply get the Sapper boilerplate and add a bunch of content so the page overflows
Unless I'm missing something I'd consider this a pretty big issue with sapper.
The text was updated successfully, but these errors were encountered: