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

Instant loading scroll restoration #1507

Closed
ofek opened this issue Mar 15, 2020 · 7 comments
Closed

Instant loading scroll restoration #1507

ofek opened this issue Mar 15, 2020 · 7 comments
Labels
bug Issue reports a bug

Comments

@ofek
Copy link
Sponsor Collaborator

ofek commented Mar 15, 2020

Description

Page refreshes do not keep your place but rather take you to the top in v5.x with the following config:

theme:
  name: material
  features:
    - instant

Expected behavior

Pressing F5 should maintain your approximate spot on the page

Actual behavior

Pressing F5 (without an anchor selected) takes you to the top

Steps to reproduce the bug

  1. Scroll down
  2. Refresh
  3. Notice your view resets

Package versions

  • Python: 3.8
  • MkDocs: 1.1
  • Material: 5.0.0rc2

Project configuration

theme:
  name: material
  features:
    - instant

System information

  • OS: Windows 10
  • Browser: Chrome
@squidfunk
Copy link
Owner

Hmm. Could you please add some more information and adhere to the issue template?

@ofek
Copy link
Sponsor Collaborator Author

ofek commented Mar 15, 2020

Done!

@squidfunk
Copy link
Owner

Perfect, thanks!

@squidfunk squidfunk added the bug Issue reports a bug label Mar 15, 2020
@squidfunk
Copy link
Owner

Should be fixed as of 4d370fe. The reason why this was happening lies in the fact that the value of history.scrollRestoration is persisted across reloads:

/* Disable automatic scroll restoration, as it doesn't work nicely */
if ("scrollRestoration" in history)
history.scrollRestoration = "manual"

The following line now hands back the task of scroll restoration to the browser before the reload:

/* Hack: ensure that page loads restore scroll offset */
fromEvent(window, "beforeunload")
.subscribe(() => {
history.scrollRestoration = "auto"
})

After the reload, scroll restoration is set back to "manual" when instant loading is enabled. The change is deployed with instant loading enabled on the deploy preview. Does it work for you?

@ofek
Copy link
Sponsor Collaborator Author

ofek commented Mar 28, 2020

It works!!!

@squidfunk
Copy link
Owner

Cool. I'll be cleaning up some stuff today and will release a final RC including all fixes made.

@squidfunk
Copy link
Owner

The fix was just released as part of RC 4. See #1498 for details.

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

No branches or pull requests

2 participants