{"record":{"id":"8521ac5b30d29a8f","repo":"oxc-project/oxc","slug":"prevent-usage-of-next-script-in-next-head-comp","errorCode":null,"errorMessage":"Prevent usage of `next/script` in `next/head` component.","messagePattern":"Prevent usage of `next/script` in `next/head` component\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/nextjs/no_script_component_in_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_script_component_in_head_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prevent usage of `next/script` in `next/head` component.\")\n        .with_help(\"See https://nextjs.org/docs/messages/no-script-component-in-head\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoScriptComponentInHead;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Prevent usage of `next/script` in `next/head` component.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// The `next/script` component should not be used in a `next/head` component.\n    /// Instead move the `<Script />` component outside of `<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_script_component_in_head.rs#L1-L30","documentation":"Warning from oxlint rule `nextjs/no-script-component-in-head`. `next/script` manages its own injection and loading priority; nesting it inside `next/head`'s `<Head>` causes double handling and ordering bugs (classic symptom: the script never runs, or runs twice). The rule reports a `Script` from `next/script` placed anywhere in the subtree of a `Head` from `next/head`.","triggerScenarios":"A `<Script>` element (imported from `next/script`) appearing as a descendant of a `<Head>` element imported from `next/head`, via the file's import specifiers.","commonSituations":"Assuming everything head-related belongs inside `<Head>`; migrating a raw `<script>` that sat in `<head>` by wrapping both in the new components at once.","solutions":["Move the `<Script>` out of `<Head>`, directly into the page or component body.","Rely on the default `afterInteractive` strategy so it loads after hydration without needing `Head` at all."],"exampleFix":"// before\nimport Head from 'next/head';\nimport Script from 'next/script';\n<Head>\n  <Script id=\"x\" src=\"/s.js\" />\n</Head>\n\n// after\n<Script id=\"x\" src=\"/s.js\" />","handlingStrategy":"validation","validationCode":"// Script nested inside next/head's Head:\n// rg -n -A4 '<Head' -g '*.tsx' src | rg '<Script'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["`next/script` and `next/head` never nest: keep Script siblings of Head, not children.","Let the default `afterInteractive` strategy handle timing instead of Head placement.","Add the nextjs plugin to CI lint so nesting is caught at PR time."],"tags":["nextjs","next-script","next-head","lint"],"backgroundTag":"lint-nested-script-in-head","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}