Mkdocs-material: Instant loading scroll restoration

Created on 15 Mar 2020  路  7Comments  路  Source: squidfunk/mkdocs-material

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
bug

All 7 comments

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

Done!

Perfect, thanks!

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

https://github.com/squidfunk/mkdocs-material/blob/4d370fe9030d5908b7a19ed84ca80b6eb65e13f5/src/assets/javascripts/index.ts#L361-L363

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

https://github.com/squidfunk/mkdocs-material/blob/4d370fe9030d5908b7a19ed84ca80b6eb65e13f5/src/assets/javascripts/index.ts#L352-L356

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?

It works!!!

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lupupitkanen picture lupupitkanen  路  4Comments

40huo picture 40huo  路  3Comments

bborysenko picture bborysenko  路  4Comments

ngtrian picture ngtrian  路  3Comments

nikramakrishnan picture nikramakrishnan  路  3Comments