-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
broken anchor false positive? #9721
Comments
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: useBrokenLinks().collectAnchor("pricing-section") Alternatively, you can also add Note that I'm not sure having multiple h1 elements on a page like you did is a good semantic html practice. |
So that means anchor errors get reported on |
No, you have to use the API for any anchor you create in your code (if you want to link to it at least, and avoid the warning (that you can turn off anyway)). What I'm saying is unrelated: it's probably not a best practice to use multiple h1 on the same page. This is unrelated to Docusaurus. |
Ok. I got it mostly working with However, there are side cases that I'd like to report. I'm not sure how you want to handle them. If I add UTM parameters, I get a broken link warning for:
I don't get a broken link warning for
Both links work. However, the correct way to format such a link is to add the query parameters first and the anchor at the end like this: Maybe the warning could explain in more detail what's wrong. The other case is if I use an anchor link in a markdown file that points to the same document like this: This also throws a warning. However, if I add the full path, it's fine: If the path ever changes to the document, that's not ideal. I think |
This is simply not a valid query parameter and Docusaurus can't know better than the URL parser itself. I presume it works because of how analytics tools work: they just do a string search for the
Really? That should not be an error. It's used extensively on our own website too. If it still happens on the latest version, maybe send another issue with a minimal repro. |
Ok about the anchor. It's not only analytics. Docusaurus opens the correct anchor when a misconfigured URL is clicked. So it's just weird that it throws the broken link error. I know that Never mind about Thanks! |
@alewolf please create repros using Docusaurus.new for each indépendant case, first to prove the issue actually exist and then so that we can study your setup in depth. Here you don't even post the error messages you get. It's not the role of Docusaurus to teach you about urls. You could also put the domain name after the anchor if you want to. Technically that is probably a valid anchor, so do we want to prevent users from doing so if it's valid bug weird? Using a ? after a # is weird but if browsers support it, we can't warn users that it is a possible mistake because some users might do that on purpose |
You don't have to teach me. Luckily I know how a "valid" URL format looks like. However, Docusaurus flags those wrongly formatted URLs as broken links, even though you admit, in reality those links work. It's not the best user experience for Docusaurus users who don't know why those broken links are flagged as broken, especially when they work. So here's a CodeSandbox example: https://codesandbox.io/p/live/3be4c123-896c-4acb-bd98-70a669f0737c |
Those are actually not wrongly formatted urls. This url is weird perfectly valid: https://docusaurus.io/docs#anchor?alsoPartOfAnchor=42 It's just that by interverting url parts you probably end up with a valid anchor that is not the one you wanted in the first place. Docuaurus will tell you that And that anchor is weird, but perfectly valid: we can't reject it because some users migth want to do these weird things that the web allow, on purpose. |
I'm experiencing something similar when updating to 3.1 using Basically all our table of content links report broken anchor
I suspect it has something to do with the trailing slash followed by an anchor tag 🤔 ? |
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 (#3915 (comment)) and see if the anchor links warnings dissapears. Thanks for the response 👍 |
I am having the same issue. Upon building the site, I get a huge number of broken anchor false positives. We haven't done anything out of the ordinary. Unfortunately, upgrading to docusaurus 3.2 didn't work, either. Did you find anything that resolved this for you @alewolf ? |
@polly-bold there are many reasons why it could happen. Not having a repro, or at least one very concrete example (ie sharing the error message + prod URL + md/link source code) makes it impossible to help you, unfortunately. What you encounter might be different from what others encounter, so it's important to share as many details as possible. Can you recreate such false positive case in a sandbox? (https://docusaurus.new/stackblitz). If not, why are you so sure these are legit false positives? Note your site https://developer.boldcommerce.com/ is publicly accessible so you could use a target URL/heading and a link as a concrete example too, but I need to see the error message for it and the source code of the markdown link being reported as broken. |
@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
We had to change the way we use the prism themes on |
Another use case that causes this issue occurs when you use - [Section One](#section-one)
- [Section Two](#section-two)
<!-- truncate -->
## Section One
Content for section one.
## Section Two
Content for section two. |
Have you read the Contributing Guidelines on issues?
Prerequisites
npm run clear
oryarn clear
command.rm -rf node_modules yarn.lock package-lock.json
and re-installing packages.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:
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.
Your environment
3.1
21.1.0
Self-service
The text was updated successfully, but these errors were encountered: