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

OnBrokenAnchors throws error for for anchors on different page. #9763

Closed
3 of 7 tasks
seezee opened this issue Jan 19, 2024 · 5 comments
Closed
3 of 7 tasks

OnBrokenAnchors throws error for for anchors on different page. #9763

seezee opened this issue Jan 19, 2024 · 5 comments
Labels
bug An error in the Docusaurus core causing instability or issues with its execution

Comments

@seezee
Copy link

seezee commented Jan 19, 2024

Have you read the Contributing Guidelines on issues?

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

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

  1. Create a page, not-this-page.js, with an anchor on it.
  2. Create a page, this-page.js, that links to the anchor on not-this-page.js. Use relative path syntax.
  3. 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
  • Operating system and version MacOS Ventura 13.6.3

Self-service

  • I'd be willing to fix this bug myself.
@seezee seezee 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 Jan 19, 2024
@slorber
Copy link
Collaborator

slorber commented 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

@slorber slorber closed this as completed Jan 19, 2024
@slorber slorber closed this as not planned Won't fix, can't repro, duplicate, stale Jan 19, 2024
@slorber slorber removed the status: needs triage This issue has not been triaged by maintainers label Jan 20, 2024
@techbridgedev
Copy link

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
Copy link
Collaborator

slorber commented Jan 22, 2024

thanks, will check later

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?

yes you can run "npm run build" in the sandbox normally

@techbridgedev
Copy link

yes you can run "npm run build" in the sandbox normally

I see; I just needed to open a second terminal. I was able to reproduce the error.

@slorber
Copy link
Collaborator

slorber commented 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:

import Link from '@docusaurus/Link';

<Link id="test-link-anchor"/>

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.

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

No branches or pull requests

3 participants