docusaurus: broken anchor false positive?
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I’m using the latest version of Docusaurus.
- I have tried the
npm run clearoryarn clearcommand. - I have tried
rm -rf node_modules yarn.lock package-lock.jsonand 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
With the new version 3.1 I get broken anchor errors, although the links work just fine. I don’t see any issue in the anchor link.
Example: On the page https://sweetcode.com/blog/are-all-payment-gateways-created-equal/ I have one link linking to the pricing section with an anchor that looks like this /plugins/pmw/#pricing-section (it also throws and error when I remove the trailing slash like this: /plugins/pmw#pricing-section
The full link with the anchor looks like this: https://sweetcode.com/plugins/pmw/#pricing-section
You’ll find the link in the document by searching for Pro version of the Pixel Manager.
Here’s the error output:
Broken anchor on source page path = /blog/are-all-payment-gateways-created-equal:
-> linking to /plugins/pmw#pricing-section
Reproducible demo
No response
Steps to reproduce
https://sweetcode.com/blog/are-all-payment-gateways-created-equal/
Expected behavior
No broken anchor error thrown on this link: https://sweetcode.com/plugins/pmw/#pricing-section
Actual behavior
A broken anchor error is thrown.
Broken anchor on source page path = /blog/are-all-payment-gateways-created-equal:
-> linking to /plugins/pmw#pricing-section
Your environment
- Public source code: na
- Public site URL: https://sweetcode.com/blog/are-all-payment-gateways-created-equal/
- Docusaurus version used:
3.1 - Environment name and version (e.g. Chrome 89, Node.js 16.4): Node version
21.1.0 - Operating system and version (e.g. Ubuntu 20.04.2 LTS): MacOS
Self-service
- I’d be willing to fix this bug myself.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 17 (4 by maintainers)
@slorber
I haven’t swizzled any components… But I have forked the remark-toc plugin in order to fix an issue with TOC not properly generating when importing other mdx files with headers of their own.
I’ve come to the conclusion to wait for 3.2 which is supposed to add some support for this case (https://github.com/facebook/docusaurus/issues/3915#issuecomment-1900862004) and see if the anchor links warnings dissapears.
Thanks for the response 👍
@polly-bold for us updating these packages to the versions used in the sandbox fixed it (not sure which one specifically, but when we only updated
@docusaurus...it wasn’t working)We had to change the way we use the prism themes on
docusaurus.config.jsbut it’s minimal, and you can see how the new version works on the sandbox.This is working as intended, cf release blog post: https://docusaurus.io/blog/releases/3.1#broken-anchors-checker
You are creating your own anchors, and fall under this case where you need to tell Docusaurus about the anchors:
Use the broken links API:
Alternatively, you can also add
onBrokenAnchors: "ignore"to your config: this will not warn you about such false positives.Note that I’m not sure having multiple h1 elements on a page like you did is a good semantic html practice.