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

Enabling the navigation.instant feature breaks links to anchors on Safari #2881

Closed
5 tasks done
damlobster opened this issue Jul 29, 2021 · 6 comments
Closed
5 tasks done
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@damlobster
Copy link

damlobster commented Jul 29, 2021

Contribution guidelines

I've found a bug and checked that ...

  • ... the problem doesn't occur with the mkdocs or readthedocs themes
  • ... the problem persists when all overrides are removed, i.e. custom_dir, extra_javascript and extra_css
  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

If the navigation.instant theme feature is enabled, links to anchors don't work as expected on Safari (MacOS and iOS). The target page is opened but the page is not scrolled to the anchor location.

Expected behaviour

When clicking a link pointing to an anchor, the page should be scrolled to that location.

Actual behaviour

The page doesn't scroll to the anchor location.

Steps to reproduce

  1. unzip reproduction.zip
  2. cd mkdocs-test
  3. mkdocs serve
  4. Open site in Safari
  5. click link A link to page1#section2

Package versions

  • Python: 3.7.3
  • MkDocs: 1.2.2
  • Material: 7.2.0

Configuration

see `reproduction.zip`

System information

  • Operating system: MacOS 11.5.1
  • Browser: Safari 14.1.2 (16611.3.10.1.3)
@squidfunk squidfunk added the needs investigation Issue must be investigated by the maintainers label Jul 29, 2021
@squidfunk
Copy link
Owner

Thanks for reporting. I've looked into it and think I may have found the cause:

  1. Links with anchors are not correctly intercepted, as they are matched against the URLs in sitemap.xml which do not contain any anchors. Thus, links with anchors always led to reloads, i.e. when linking between documents or searching.
  2. When an URL is intercepted and contains an anchor, the anchor was used for positioning. However, the order of operation was wrong, as the anchor was set before the document was replaced, so the browser did not set the offset correctly.

Interestingly, the combination of 1. and 2. seems to have led to the strange behavior in Safari, not in Chrome.

adafd84 is an attempt to fix this:

  1. URLs are canonicalized before comparing them with the URLs from sitemap.xml.
  2. When an URL contains an anchor, the position is now set after document replacement.

This means that anchors are finally working with instant loading, even in search results. In regard to search results, this was something I had on my list for a long time and it seems that this is now finally fixed. I hope that this did not introduce other bugs – instant loading is actually extremely tricky to get right. I will revisit instant loading at a later time.

Please check master to verify that this is fixed. I will issue a release then shortly.

@squidfunk squidfunk added bug Issue reports a bug resolved Issue is resolved, yet unreleased if open and removed needs investigation Issue must be investigated by the maintainers labels Aug 7, 2021
@squidfunk
Copy link
Owner

I went ahead and released the fix as part of 7.2.3.

@ybizeul
Copy link

ybizeul commented Apr 3, 2022

I'm having that issue with current version.
Anchors working fine on Safari without navigation.instant but breaks with it.

Running 8.2.8

@squidfunk
Copy link
Owner

Thanks for reporting. Could you please check which version introduced the error? If you find the version that introduced the issue, please create a new issue and provide a minimal reproducible example.

@ybizeul
Copy link

ybizeul commented Apr 4, 2022

Thanks. 7.0.0 is introducing this behaviour, will open a new issue with sample

@ybizeul
Copy link

ybizeul commented Apr 4, 2022

#3797

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

No branches or pull requests

3 participants