{"record":{"id":"c8e02c27b8b557aa","repo":"oxc-project/oxc","slug":"prevent-usage-of-title-with-head-component-f","errorCode":null,"errorMessage":"Prevent usage of `<title>` with `Head` component from `next/document`.","messagePattern":"Prevent usage of `<title>` with `Head` component from `next/document`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/nextjs/no_title_in_document_head.rs","lineNumber":12,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{ImportDeclarationSpecifier, JSXChild, JSXElementName},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_title_in_document_head_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prevent usage of `<title>` with `Head` component from `next/document`.\")\n        .with_help(\"See https://nextjs.org/docs/messages/no-title-in-document-head\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoTitleInDocumentHead;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Prevent usage of `<title>` with `Head` component from `next/document`.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// A `<title>` element should only be used for any `<head>` code that is common for all pages.\n    /// Title tags should be defined at the page-level using `next/head` instead.\n    ///\n    /// ### Examples","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/nextjs/no_title_in_document_head.rs#L1-L30","documentation":"Warning from oxlint rule `nextjs/no-title-in-document-head`. `pages/_document.js` is shared by every route, so a `<title>` inside its `<Head>` pins one title app-wide and fights per-page titles set via `next/head`. The rule reports `<title>` elements placed inside a `Head` imported from `next/document`.","triggerScenarios":"A `<title>` JSX element whose ancestor is a `<Head>` component imported from `next/document` — i.e. inside the custom document.","commonSituations":"Setting a default site title while scaffolding `_document.js`; misunderstanding that per-page titles must live in each page, not the shared document.","solutions":["Delete the `<title>` from `pages/_document.js`.","Set titles per page with `next/head`, or with `export const metadata = { title }` in the app router."],"exampleFix":"// before (pages/_document.js)\n<Head><title>My App</title></Head>\n\n// after (pages/index.js)\nimport Head from 'next/head';\n<Head><title>Home | My App</title></Head>","handlingStrategy":"validation","validationCode":"// title inside the document's Head:\n// rg -n -A6 'from .next/document.' pages/_document.* | rg '<title'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Titles live per page (`next/head`) or in app-router `metadata`, never in `_document.js`.","When scaffolding the custom document, start from the official template without a title.","Run oxlint with the nextjs plugin in CI to catch a stray title immediately."],"tags":["nextjs","seo","pages-router","lint"],"backgroundTag":"lint-document-title-placement","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"}