Skip to content

onBrokenAnchors reports spurious broken anchors for every page #9880

Closed

Description

@Zamiell

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

Steps to reproduce:

git clone https://github.com/hanabi/hanabi.github.io.git
cd hanabi.github.io
git checkout 6f882595d54f26a2a99cb9d70f9a4e35b88c01d0
yarn
docusaurus build

Then you will get the following output:

[WARNING] Docusaurus found broken anchors!

Please check the pages of your site in the list below, and make sure you don't reference any anchor that does not exist.
Note: it's possible to ignore broken anchors with the 'onBrokenAnchors' Docusaurus configuration, and let the build pass.

Exhaustive list of all broken anchors found:
- Broken anchor on source page path = /about:
   -> linking to #other-quick-links (resolved as: /about#other-quick-links)
   -> linking to #hotkeys (resolved as: /about#hotkeys)
   -> linking to #contributing (resolved as: /about#contributing)

However, no such link exists in the about.mdx file, so Docusaurus is drunk.

Your environment

Self-service

  • I'd be willing to fix this bug myself.

Activity

  1. added
    bug
    status: needs triage
    on Feb 23, 2024
  2. OzakIOne commented on Feb 23, 2024

    @OzakIOne
    Contributor

    Hello, I've tried to replicate your project locally however, by following your instructions, I have an error related to python, I don't know how to fix this error neither why you need python.

    Could you provide a smaller source code with the strict minimum required to run Docusaurus so that we can debug knowing the error can't come from an external dependency

  3. slorber commented on Feb 23, 2024

    @slorber
    Collaborator

    It looks like your site has a weird behavior regarding heading anchors: the # heading icon is not showing on hover and the HTML structure is different too.

    This is very likely the reason.

    CleanShot 2024-02-23 at 12 17 34

    CleanShot 2024-02-23 at 12 15 40

    I don't understand how you modified your site, but it is not the standard behavior so you probably did something.

    If you have a custom theme heading component, make sure to use the newly documented hook in it:

    https://docusaurus.io/docs/docusaurus-core#useBrokenLinks

    export default function Heading({as: As, id, ...props}: Props): JSX.Element {
      useBrokenLinks().collectAnchor(id);
      return <As id={id} {...props}/>;		
    }
  4. Zamiell commented on Feb 23, 2024

    @Zamiell
    ContributorAuthor

    I'll work on a more minimal reproduction, thanks.

  5. removed
    status: needs triage
    on Feb 23, 2024
  6. polly-bold commented on Apr 10, 2024

    @polly-bold

    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 @Zamiell ?

  7. Zamiell commented on Apr 10, 2024

    @Zamiell
    ContributorAuthor

    iirc i had some other dep that got upgraded which caused this to happen

  8. slorber commented on Apr 11, 2024

    @slorber
    Collaborator

    Similar answer to #9721 (comment), we need more info to troubleshoot such problem.

    Yes, third-party plugins can also be the cause of such false positives. In which case it's helpful to share which plugins you are using so that we can inspect their code.

  9. erenkan commented on Oct 1, 2024

    @erenkan

    Another use case that causes this issue occurs when you use before the titles. On the main blog page, the anchors cannot find the related links, which results in an error. @slorber

    - [Section One](#section-one)
    - [Section Two](#section-two)
    
    <!-- truncate -->
    
    ## Section One
    
    Content for section one.
    
    ## Section Two
    
    Content for section two.
  10. slorber commented on Oct 1, 2024

    @slorber
    Collaborator

    @erenkan this is another bug reported here: #10287

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