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

Markdown Header Anchor Links do not work on page load #2399

Closed
Noah-Silvera opened this issue Mar 10, 2020 · 9 comments · Fixed by #2478
Closed

Markdown Header Anchor Links do not work on page load #2399

Noah-Silvera opened this issue Mar 10, 2020 · 9 comments · Fixed by #2478
Labels
bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers

Comments

@Noah-Silvera
Copy link
Contributor

Noah-Silvera commented Mar 10, 2020

🐛 Bug Report

Each markdown header has a targeted anchor link which corresponds to a URL.
i.e. http:///docs/mobile/doc1#header1

If you click on the headers in the right sidebar when the documentation is loaded, the page scrolls to the header that is the anchor link target as expected.

But, if you copy a link to one of the headers with a anchor # in it, and paste it into a new tab, the page does not scroll to the appropriate header on page load.

Have you read the Contributing Guidelines on issues?

yes

To Reproduce

  1. Create a new site using npx @docusaurus/init@next init test-site classic
  2. yarn start
  3. Open http://localhost:3000/docs/doc1#admonitions

Expected behavior

The page doc1 is opened and scrolled to the admonitions header

Actual Behavior

The page doc1 is opened but not scrolled to the admonitions header

Your Environment

  • Docusaurus version used:
    "@docusaurus/core": "^2.0.0-alpha.48",
    "@docusaurus/preset-classic": "^2.0.0-alpha.48",
  • Chrome Version 80.0.3987.132
  • Windows 10 Desktop

Reproducible Demo

This repo is an unmodified npx @docusaurus/init@next init test-site classic but including for completeness
https://github.com/Noah-Silvera/docusaurus-anchor-links-bug

@Noah-Silvera Noah-Silvera added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Mar 10, 2020
@lex111
Copy link
Contributor

lex111 commented Mar 11, 2020

Is there a similar bug on the builded website? This should be relevant only in development mode.

@Noah-Silvera
Copy link
Contributor Author

No there is no similar bug in prod. It only affects development mode.

@lex111
Copy link
Contributor

lex111 commented Mar 11, 2020

In dev mode, we do not use SSR, so this issue occurs. I do not think this is a serious bug, since there is no such thing in the production build. This may not be very comfortable, although it is unlikely that you will often use anchors links in dev mode 🤷‍♂️.

@Noah-Silvera
Copy link
Contributor Author

Should we just close this issue then? Seems very minor if it only affects dev mode.
Might be worth documenting under https://v2.docusaurus.io/docs/markdown-features#markdown-headers?

@Mauriceac
Copy link

I have this bug even after building.

Any workaround (other than refreshing, which effectively works)?

@jsphstls
Copy link

jsphstls commented Aug 24, 2021

I see the same bug for builds with "@docusaurus/core": "2.0.0-beta.4"

Edit:
Anchor links are working in both dev and prod mode once I moved all official @docusaurus/* packages to the exact same version as per the output warning. The anchor link must also be lowercase, despite VsCode accepting any case when moving between markdown files. CC @Mauriceac

@jsphstls
Copy link

I found a cross-page anchor link that is working on the current Docusaurus site. See the “multi-instance plugins” link under https://docusaurus.io/docs/blog#multiple-blogs.

@k8w
Copy link

k8w commented Nov 28, 2021

Still have this problem, latest version

@Mauriceac
Copy link

Mauriceac commented Nov 29, 2021

Still have this problem, latest version

@k8w, me too. You might want to follow issue 3081. It explains the problem, although no solution has been given yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants