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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 ofwindow.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!