Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] properly scroll if body has margin #2761

Merged
merged 3 commits into from
Nov 11, 2021
Merged

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Nov 9, 2021

Fixes #2760

Changes

  • Fixed my dumb tests update mistake from my last PR (tests were actually failing)
  • Use document.documentElement instead of document.body when checking for max scroll y
  • Also fixes another sizable bug I found: When scrolling to/near the end of a page, the new page after navigation would also be scrolled to/near the end of the page by the browser regardless of the new page scroll height. Added extra checks for that.

Note: We may need to find a robust way to check for scrolling before the page onMount() runs. The pageYOffset trick is starting to bite us.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@bluwy bluwy added the router label Nov 9, 2021
@changeset-bot
Copy link

changeset-bot bot commented Nov 9, 2021

🦋 Changeset detected

Latest commit: de4aacf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@bluwy
Copy link
Member Author

bluwy commented Nov 9, 2021

@benmccann I made quite a big change since your review. The main takeaways are noted in the PR description, and in the code comments. I feel like the implementation is starting to get hacky, but unless we find a better way, we may have to stick with it for now.

@bluwy bluwy marked this pull request as ready for review November 9, 2021 18:18
@bluwy bluwy requested a review from benmccann November 9, 2021 18:18
@gavinr
Copy link

gavinr commented Nov 11, 2021

Thank you @bluwy for this PR. I really appreciate your work on this project. Can I help this PR to land by testing or anything? Or are we just waiting on a review?

@bluwy
Copy link
Member Author

bluwy commented Nov 11, 2021

Thanks @gavinr. Yeah I'm currently waiting for Ben's review as he has more experience with the router. If you can help test this branch, that would be nice as well to bring more confidence in the PR.

Copy link

@gavinr gavinr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested this with the reproduction case in #2760 and it does resolve that issue. Thank you!

@Rich-Harris Rich-Harris merged commit 82bfb5e into master Nov 11, 2021
@Rich-Harris Rich-Harris deleted the fix-router-scroll-2 branch November 11, 2021 22:02
@Rich-Harris
Copy link
Member

niiiice, amazing work

@antony
Copy link
Member

antony commented Nov 11, 2021

game changer! @Wolfr check this.

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

Successfully merging this pull request may close these issues.

Scroll issue when navigating between pages
5 participants