{"record":{"id":"db486f2613d7edae","repo":"oxc-project/oxc","slug":"do-not-include-multiple-instances-of-head","errorCode":null,"errorMessage":"Do not include multiple instances of `<Head/>`","messagePattern":"Do not include multiple instances of `<Head/>`","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/nextjs/no_duplicate_head.rs","lineNumber":10,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::{LabeledSpan, OxcDiagnostic};\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::AstNode;\nuse oxc_span::GetSpan;\n\nuse crate::{context::LintContext, rule::Rule};\n\nfn no_duplicate_head(labels: Vec<LabeledSpan>) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not include multiple instances of `<Head/>`\")\n        .with_help(\"Only use a single `<Head />` component in your custom document in `pages/_document.js`. See: https://nextjs.org/docs/messages/no-duplicate-head\")\n        .with_labels(labels)\n}\n#[derive(Debug, Default, Clone)]\npub struct NoDuplicateHead;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Prevent duplicate usage of `<Head>` in `pages/_document.js`.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// This can cause unexpected behavior in your application.\n    ///\n    /// ### Examples\n    ///\n    /// Examples of **incorrect** code for this rule:","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/nextjs/no_duplicate_head.rs#L1-L28","documentation":"Warning from oxlint rule `nextjs/no-duplicate-head`. In `pages/_document.js`, each `<Head>` imported from `next/document` produces its own server-rendered head context; more than one yields duplicate or conflicting head markup. The rule counts `Head` usages in the custom document and, when there are two or more, reports every occurrence with a label on each.","triggerScenarios":"Two or more `<Head>...</Head>` elements (from `next/document`) rendered anywhere in `pages/_document.js`, including inside fragments or conditionals.","commonSituations":"Splitting the document into sections and giving each its own `<Head>`; pasting a meta block into a second Head; merging markup from two tutorials.","solutions":["Merge the children of every `<Head>` block into a single `<Head>` in `_document.js`.","Keep only document-wide tags (charset, viewport) there; move page-specific tags to `next/head` in each page."],"exampleFix":"// before\n<Html>\n  <Head><meta charSet=\"utf-8\" /></Head>\n  <body><Main /><NextScript />\n    <Head><title>extra</title></Head>\n  </body>\n</Html>\n\n// after\n<Html>\n  <Head><meta charKey=\"utf-8\" /><title>extra</title></Head>\n  <body><Main /><NextScript /></body>\n</Html>","handlingStrategy":"validation","validationCode":"// count Head blocks in the custom document:\n// rg -c '<Head' pages/_document.tsx   # any count > 1 needs merging","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep exactly one `<Head>` per custom document; treat a second as a merge task.","Put page-specific tags in that page's `next/head`, never in `_document.js`.","Lint `_document.js` in CI with the nextjs plugin."],"tags":["nextjs","pages-router","seo","lint"],"backgroundTag":"lint-duplicate-element","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}