Skip to content

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

Closed as not planned

Description

@seezee

Have you read the Contributing Guidelines on issues?

Prerequisites

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.

Activity

  1. added
    bug
    status: needs triage
    on Jan 19, 2024
  2. slorber commented on Jan 19, 2024

    @slorber
    Collaborator

    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

  3. removed
    status: needs triage
    on Jan 20, 2024
  4. techbridgedev commented on Jan 22, 2024

    @techbridgedev

    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?

  5. slorber commented on Jan 22, 2024

    @slorber
    Collaborator

    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

  6. techbridgedev commented on Jan 22, 2024

    @techbridgedev

    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.

  7. slorber commented on Jan 23, 2024

    @slorber
    Collaborator

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions