Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

goto doesn't reset scroll position #1130

Closed
antony opened this issue Mar 24, 2020 · 4 comments
Closed

goto doesn't reset scroll position #1130

antony opened this issue Mar 24, 2020 · 4 comments

Comments

@antony
Copy link
Member

antony commented Mar 24, 2020

Describe the bug
When calling goto from your code, when the page is scrolled such that the top of it is off screen, and navigating to an equally long page, the scroll position is not reset to 0, even if the page has not been visited before.

To Reproduce
Create two pages of 200% length with a button at the bottom. Cause the button to call goto passing the next page as a parameter.

Expected behavior
I would expect goto to default to scrolling the page to the top on navigation, especially if the page has not been visited before.

Information about your Sapper Installation:
Google Chrome | 80.0.3987.132 (Official Build) (64-bit)
OS | Linux

  • Sapper version (Please check you can reproduce the issue with the latest release!)

0.27.11

  • Svelte version (Please check you can reproduce the issue with the latest release!)

3.20.1

  • If it is an exported (npm run export) or dynamic application.

Dynamic

  • Whether your application uses Webpack or Rollup

Rollup

Severity

I can work around it with:

      await goto('/some-page')
      window.scrollTo(0, 0)

so not too critical.

@PierBover
Copy link

It would be great if there was an option to do it since this is a very common problem with SPA routers.

Something like:

goto('/something', {resetScroll: true});

@Jayphen
Copy link
Contributor

Jayphen commented Jul 15, 2020

Is this still valid? This actually describes the inverse of the current behaviour.

I have written a test as part of this PR that shows that goto scrolls to 0,0 by default.

The PR adds an option to preserve the scroll position.

@benmccann
Copy link
Member

@antony I think this was fixed by #1320, so I'm going to close this. Let me know if it's still an issue

@Jayphen
Copy link
Contributor

Jayphen commented Aug 28, 2020

I’ve noticed that the scroll position does not get set to the top after redirecting with this.redirect. I’ll make a separate issue and repro; not sure it’s related to the OP here

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants