Skip to content

client-redirects-plugin doesn't support hash fragments in FROM attribute #11052

Description

@ZenaMel

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

Based on the PR 9171 (issue #6845) This should be solved but isn't in Docusaurus v3.7.0 ("@docusaurus/plugin-client-redirects": "^3.7.0")

Stacktrace:

[ERROR] [Error [ValidationError]: "redirects[0].from" (/Load-Management/DLM/#hierarchial-dlm) is not a valid pathname. Pathname should start with slash and not contain any domain or query string.] {
  _original: {
    fromExtensions: [ 'html', 'htm' ],
    redirects: [
      {
        from: '/Load-Management/DLM/#hierarchial-dlm',
        to: '/Load-Management/DLM/dlm-hierarchical'
      },
      {
        from: '/Load-Management/DLM/#solar-dlm',
        to: '/Load-Management/DLM/dlm-solar'
      }
    ]
  },
  details: [
    {
      message: '"redirects[0].from" (/Load-Management/DLM/#hierarchial-dlm) is not a valid pathname. Pathname should start with slash and not contain any domain or query string.',
      path: [ 'redirects', 0, 'from' ],
      type: 'any.custom',
      context: {
        error: Error
            at C:\WS-Bender\PRODUCT-DOCS\node_modules\@docusaurus\utils-validation\lib\validationSchemas.js:66:15
            at Object.validate (C:\WS-Bender\PRODUCT-DOCS\node_modules\joi\lib\types\any.js:47:28)
            at internals.rules (C:\WS-Bender\PRODUCT-DOCS\node_modules\joi\lib\validator.js:494:33)
            at exports.validate (C:\WS-Bender\PRODUCT-DOCS\node_modules\joi\lib\validator.js:450:22)
            at internals.Base.$_validate (C:\WS-Bender\PRODUCT-DOCS\node_modules\joi\lib\base.js:774:26)
            at Object.validate (C:\WS-Bender\PRODUCT-DOCS\node_modules\joi\lib\types\alternatives.js:115:44)
            at exports.validate (C:\WS-Bender\PRODUCT-DOCS\node_modules\joi\lib\validator.js:425:26)
            at internals.Base.$_validate (C:\WS-Bender\PRODUCT-DOCS\node_modules\joi\lib\base.js:774:26)
            at Object.validate (C:\WS-Bender\PRODUCT-DOCS\node_modules\joi\lib\types\keys.js:108:45)
            at exports.validate (C:\WS-Bender\PRODUCT-DOCS\node_modules\joi\lib\validator.js:425:26),
        label: 'redirects[0].from',
        value: '/Load-Management/DLM/#hierarchial-dlm',
        key: 'from'
      }
    }
  ]
}
[INFO] Docusaurus version: 3.7.0
Node version: v21.5.0
error Command failed with exit code 1.

Reproducible demo

No response

Steps to reproduce

set redirects that have a hash fragment, e.g.,

/**
 * Docusaurus redirect rules for @docusaurus/plugin-client-redirects
 * Format: { from: string | string[], to: string }
 */

module.exports = [
    {
        from: '/Load-Management/DLM/#hierarchial-dlm',
        to: '/Load-Management/DLM/dlm-hierarchical',
    },
    {
        from: '/Load-Management/DLM/#solar-dlm',
        to: '/Load-Management/DLM/dlm-solar',
    },
];

Expected behavior

Working redirects.

Actual behavior

Validation error.

Your environment

  • Docusaurus version used: 3.7.0

Self-service

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its executionclosed: wontfixA fix will bring significant overhead, or is out of scope (for feature requests)

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions