-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
View Transitions: use history.scrollRestoration="manual" #8231
View Transitions: use history.scrollRestoration="manual" #8231
Conversation
🦋 Changeset detectedLatest commit: 25c81e1 The changes in this PR will be included in the next version bump. 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 |
Perfect, thank you! |
@martrapp this sound right to you? |
Even more generally, this fixes page jumping for all SPA page transitions when using back / forward navigation. The morph transitions were just the most noticeable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Looks great!
Hi @justinbeaty! Thanks a lot for the PR. I wasn't really able to see what scrolling is suppressed by In its current form, the PR breaks the in-page history navigation (back/forward between links to fragments on the same page). Currently, we only actively handle navigation between different pages. |
@martrapp Here's a reproducible example: https://github.com/justinbeaty/astro-scroll-restoration-mwe There's also the Here's a video before the PR. Notice how the colored box jumps around, and also you can see flashes of red (from the footer) in some cases. bug-compressed.mp4Here's a video after: with-pr-compressed.mp4I will investigate the hash fragment issue, but I'm quite certain |
Quite a difference, thank you for the examples. |
That might be an easy solution, otherwise we have to pushState on fragment changes, but avoid fetching the page. But that's a pretty significant refactor it seems like. |
@justinbeaty Hi Justin, do you see a chance to update your PR? |
@martrapp Hi Martin, I just tried this on my minimal reproducible repo, which seems like it might in fact resolve the issue. I've only done light testing so I could be missing something (much like I missed the issues with the hash fragments in the first place.) justinbeaty/astro-scroll-restoration-mwe@844e635 (Note: if you clone this project, there's a I can update this PR with that change as well if there's not a cleaner way to do this. I'm also not opposed to a replacement PR or commit by the Astro team if the solution is more involved. I haven't fully grokked the |
@justinbeaty I'm sure that resetting scrollRestoration to "auto" at the beginning of the click handler and adding "manual" scroll restoration just before the two pushStates is a real improvement! In fact, this might also be necessary to solve another scrolling issue. Currently I don't see any chance that your change would make anything worse ;-) Thanks to your discovery, the issue with the hash fragments is now covered by the e2e tests. You found the bug and I would be happy to see your updated PR in the code base ;-) |
Co-authored-by: Martin Trapp <[email protected]>
@martrapp Done, I'm glad to know that it might fix another bug too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Changes
history.scrollRestoration = "manual";
to tell the browser we'll take care of the scroll position ourselves.Testing
transition:name
Docs