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

On-page anchor scroll can result in incorrect URL shift with certain headings #134

Closed
mattstein opened this issue Jan 12, 2021 · 2 comments
Assignees
Labels
🐞 bug Something isn't working

Comments

@mattstein
Copy link
Contributor

mattstein commented Jan 12, 2021

Description

From @engram-design in Discord:

Not sure if this has been reported yet, but I'm noticing that after clicking on a heading in the docs, it scrolls to that heading, the url fragment changed, but 5 seconds later changes back? For example, heading to https://craftcms.com/docs/commerce/3.x/orders-carts.html#carts - scroll down the page and click on any heading. The URL will change to reflect the new heading, but will flick back to the original URL. Clicking on the heading "#" again will update the URL correctly.

Notably, this looks like an issue with H3 links, the H2 ones are fine

Heading levels beyond the sidebar navigation result in weird behavior because of a workaround for another VuePress scroll bug. All heading levels should be registered and handled consistently.

Steps to reproduce

  1. Visit page like Orders & Carts whose content uses heading levels deeper than right sidebar links.
  2. Choose any link next to an h3+ heading.
  3. Observe correct URL in address bar, but moments later it reverts to nearest higher-level anchor.
@mattstein mattstein added the 🐞 bug Something isn't working label Jan 12, 2021
@mattstein
Copy link
Contributor Author

Definitely related to @vuepress/active-header-links.

@mattstein mattstein self-assigned this Jan 15, 2021
@mattstein
Copy link
Contributor Author

The active header links plugin assumes that all heading anchors have corresponding links in the sidebar, and uses those pairings to forcibly update the URL hash while scrolling page content. Modified the plugin to evaluate all heading anchors when updating the URL hash and ignore the sidebar relationship altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant