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

Anchor links across pages are failing #5020

Closed
5 tasks done
teikjun opened this issue Jun 20, 2021 · 1 comment · Fixed by #5023
Closed
5 tasks done

Anchor links across pages are failing #5020

teikjun opened this issue Jun 20, 2021 · 1 comment · Fixed by #5023
Labels
bug An error in the Docusaurus core causing instability or issues with its execution

Comments

@teikjun
Copy link
Contributor

teikjun commented Jun 20, 2021

🐛 Bug Report

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io
  • I have read the console error message carefully (if applicable)

Description

Anchor links that target headers in other pages are failing. Instead of sending users to the target header, users are sent to the top of the page.

Have you read the Contributing Guidelines on issues?

Yes

Steps to reproduce

  1. Go to this link: https://docusaurus.io/docs/using-themes#writing-customized-docusaurus-themes
  2. Click on getThemePath()

image

Expected behavior

Expected to go to the target header

Actual behavior

Get sent to the top of the page
image

Your environment

  • Docusaurus version used: 2.0.0-beta.1
  • Environment name and version (e.g. Chrome 78.0.3904.108, Node.js 10.17.0): Firefox 89, Chrome 91

Reproducible Demo

Demo 1

  1. Go to https://deploy-preview-4797--docusaurus-2.netlify.app/docs/using-themes#writing-customized-docusaurus-themes
  2. Click on the getThemePath() link

Demo 2

  1. Go to https://deploy-preview-4811--docusaurus-2.netlify.app/docs/deployment#self-hosting
  2. Click on the docusaurus serve link

Root Causes

There are 2 root causes here - they correspond to the 2 demos above.

Root cause for Demo 1

PR #4797 is the earliest PR that has the bug, so I believe it is the root cause of the regression. Adding back the !hash condition (as shown below) resolves this bug, but I'm not sure if this is the right approach.

image

@lex111 @slorber, could I get your advice on this? 🙏

Root cause for Demo 2

Demo 2 is the state before PR #4797 was merged. Certain anchor links still fail. This is due to incorrect anchor link specified on the user side. I will open a PR to resolve this.

@teikjun teikjun 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 Jun 20, 2021
@lex111
Copy link
Contributor

lex111 commented Jun 20, 2021

@teikjun thanks for the report, yes, you're right, we should ignore hash changes in that hook, my bad, will be fixed in #5023.

@Josh-Cena Josh-Cena removed the status: needs triage This issue has not been triaged by maintainers label Feb 22, 2022
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants