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

Fix deeplinks no matter previous scroll position #1139

Merged
merged 1 commit into from
May 4, 2020

Conversation

ArkaneMoose
Copy link
Contributor

Hello, and thanks for this awesome tool! I found what appears to be a bug in anchor deeplinks.

See a demo of the broken behavior and the fixed behavior.

2020-04-01 12-39-05

If you're scrolled down on one page, and you click a deeplink that goes to a different page, the scroll position on the new page is wrong. This might be what is being referred to in the "anchor linking" part of #784, but I'm not quite sure.

This broken behavior seems to be because of this line which computes the new scroll position according to the getBoundingClientRect().top of the deeplinked element. According to MDN, this value is relative to the top-left of the viewport, so if you want a position that is relative to the top-left of the document, you need to add the value of window.scrollY.

This PR implements that, and it also adds a test that verifies that the behavior is broken prior to this PR and fixed afterwards.

Let me know if there's anything you'd like me to change. Thanks!

@Conduitry Conduitry merged commit 3bf058c into sveltejs:master May 4, 2020
@Conduitry
Copy link
Member

Released in 0.27.13, thanks!

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

Successfully merging this pull request may close these issues.

3 participants