Skip to content

headTags config validation rejects boolean HTML attribute values #12233

Closed

Description

@DhineshPonnarasan

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

The headTags configuration rejects boolean HTML attribute values during validation, despite three pieces of evidence showing this is unintentional:

  1. TypeScript types allow booleans — @docusaurus/types defines attributes?: Partial<{[key: string]: string | boolean}>
  2. Renderer handles booleans — packages/docusaurus/src/server/htmlTags.ts:68-70 explicitly handles boolean attributes, rendering true as the attribute name alone and false as omitted
  3. Sibling scripts config accepts booleans — configValidation.ts uses .unknown() which allows boolean values, and the docs say "you might want to add async: true/defer: true"

Reproducible demo

https://new.docusaurus.io — create a new project and add the headTags config shown below.

Steps to reproduce

  1. Create a fresh Docusaurus project:
npx [email protected] my-repro classic --javascript
cd my-repro
  1. Add this to docusaurus.config.js:
const config = {
  headTags: [
    {
      tagName: 'script',
      attributes: {
        src: '/analytics.js',
        async: true,
      },
    },
  ],
  // ... rest of config
};
  1. Run:
npm run build

Expected behavior

The configuration should accept valid HTML boolean attributes such as async, defer, and disabled, consistent with the published TypeScript types and rendering behavior.

Actual behavior

Build fails with:

[ERROR] Error: "headTags[0].attributes.async" must be a string

The validation schema uses Joi.string() which restricts all attribute values to strings, contradicting the TypeScript type definition and the renderer's boolean handling.

Your environment

  • Docusaurus: 3.10.1 (npm release)
  • Node.js: v24.14.0
  • Package manager: npm
  • OS: Windows 11

Self-service

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

Activity

  1. added
    bug
    status: needs triage
    on Jul 7, 2026
  2. ATKasem commented on Jul 7, 2026

    @ATKasem
    Contributor

    Hello! 👋 @DhineshPonnarasan

    I’m going to move forward with a small PR for this.

    The change will be narrowly scoped to updating headTags.attributes validation so it accepts string | boolean, matching the existing HtmlTagObject type and renderer behavior. I’ll also add focused validation test coverage.

    This won’t broaden the schema to arbitrary attribute values; unsupported attribute value types will still be rejected.

  3. ATKasem commented on Jul 7, 2026

    @ATKasem
    Contributor

    Opened a focused PR for this: #12237

    The change is limited to allowing headTags.attributes values to be string | boolean, matching the existing public type and renderer behavior, with focused validation coverage.

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

    bugstatus: needs triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions