Skip to content

Documentation should also teach registering anchors in plugin code #9986

Open
@danielspofford

Description

@danielspofford

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

  • I am currently getting warnings from onBrokenLinks/onBrokenAnchors. This is what I am ultimately trying to fix.
  • Docusaurus doesn't know about them because they link to content that is generated at build time by another plugin that is incapable of using official Link/etc components that track this automatically.
  • Docusaurus docs push me in the direction of https://docusaurus.io/docs/docusaurus-core#useBrokenLinks to handle a scenarios like this.
  • Problem is I cannot seem to useBrokenLinks in a plugin. Hopefully I am just doing something wrong, but I am not even sure if I am supposed to be able to use this functionality in a plugin given "Docusarus Client API"; does that mean that functionality cannot be used in plugins?

In any case: is it possible to useBrokenLinks in a plugin? If yes, how/what am I doing wrong? If no, is it possible to solve my problem with a plugin (inform docusaurus of routes that are valid so that it doesn't warn/throw on them with onBrokenLinks/onBrokenAnchors).

Reproducible demo

https://codesandbox.io/p/devbox/jovial-benji-f4599g

Steps to reproduce

  1. Add a no-op plugin that tries to import useBrokenLinks like the codesandbox has at src/plugins/foo/index.js.
  2. Add the plugins: ['src/plugins/foo'] to docusuarus config.

If using the codesandbox link I provide - the above steps are already done (and are the only changes to the sandbox). The project as-is in there will fail to build.

Expected behavior

I hoped to use useBrokenLinks in a plugin to inform docusaurus about anchors/links that it should consider valid to stop receiving false onBrokenLinks/onBrokenAnchors warnings.

Actual behavior

Docusaurus fails to build - it cannot resolve the import of useBrokenLinks in a plugin.

  [cause]: Error: Docusaurus could not load module at path "myproject/src/src/plugins/foo/index.js"
  Cause: Cannot find module '@docusaurus/useBrokenLinks'

Long form: https://gist.github.com/danielspofford/17993f7c77319d3639d52a8fd9f28fc3.

Your environment

Self-service

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationThe issue is related to the documentation of Docusaurus

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions