You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OnBrokenAnchors throws error for for anchors on different page. #9763
I have read the console error message carefully (if applicable).
Description
When linking like this, [A link to an anchor on another page](/docs/not-this-page/#some-anchor), enabling onBrokenAnchors: 'throw' causes builds to fail.
Reproducible demo
No response
Steps to reproduce
Create a page, not-this-page.js, with an anchor on it.
Create a page, this-page.js, that links to the anchor on not-this-page.js. Use relative path syntax.
Run build.
Expected behavior
Legitimate links to anchors on another page should not throw an error. Build should succeed.
Actual behavior
Legitimate links to anchors on another page throw an error; builds fail.
Your environment
Public source code: repository is private
Public site URL: techbridge-docs.vercel.app
Docusaurus version used: 3.1.0
Environment name and version Chrome 120.0.6099.234, Node.js 18.7.0
Although it doesn't seem not super practical, it is working as intended, cf my comment here: #9721 (comment)
You need to use useBrokenLinks().collectAnchor("another-anchor") on the page to make sure Docusaurus is aware of this anchor.
Thanks to (#9732), when Docusaurus 3.1.1 is released (later this week?) you should be able to use Docusaurus Link component to make it more convenient in practice to create anchors:
We'll investigate later how we could make it possible to automatically collect anchors so that you don't have to care about it, but for now you have to collect all anchors manually for the broken link checker to know about them, or use the @theme/Heading (Markdown heading) or the <Link> component.
Activity
slorber commentedon Jan 19, 2024
please create a repro using docusaurus.new.
The repro steps are too vague to act on. We don't even know the content of the files.
We'll reopen if a repro is provided
techbridgedev commentedon Jan 22, 2024
I've opened a repo at https://codesandbox.io/p/devbox/great-brahmagupta-q5kf5c.
However, since the error is thrown only during a build, I'm unable to test or duplicate the error. Is there a way to trigger a build on the sandbox?
slorber commentedon Jan 22, 2024
thanks, will check later
yes you can run "npm run build" in the sandbox normally
techbridgedev commentedon Jan 22, 2024
I see; I just needed to open a second terminal. I was able to reproduce the error.
slorber commentedon Jan 23, 2024
Although it doesn't seem not super practical, it is working as intended, cf my comment here: #9721 (comment)
You need to use
useBrokenLinks().collectAnchor("another-anchor")on the page to make sure Docusaurus is aware of this anchor.Thanks to (#9732), when Docusaurus 3.1.1 is released (later this week?) you should be able to use Docusaurus Link component to make it more convenient in practice to create anchors:
We'll investigate later how we could make it possible to automatically collect anchors so that you don't have to care about it, but for now you have to collect all anchors manually for the broken link checker to know about them, or use the
@theme/Heading(Markdown heading) or the<Link>component.