{"record":{"id":"24eb370d51266033","repo":"oxc-project/oxc","slug":"next-script-components-with-inline-content-must","errorCode":null,"errorMessage":"`next/script` components with inline content must specify an `id` attribute.","messagePattern":"`next/script` components with inline content must specify an `id` attribute\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/nextjs/inline_script_id.rs","lineNumber":13,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Expression, JSXAttributeItem, JSXAttributeName, ObjectPropertyKind, PropertyKey},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse rustc_hash::FxHashSet;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn inline_script_id_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"`next/script` components with inline content must specify an `id` attribute.\",\n    )\n    .with_help(\"See https://nextjs.org/docs/messages/inline-script-id\")\n    .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct InlineScriptId;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Enforces that all `next/script` components with inline content or `dangerouslySetInnerHTML` must have an `id` prop.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Next.js requires a unique `id` prop for inline scripts to properly deduplicate them during page renders.\n    /// Without an `id`, the same inline script might be executed multiple times, leading to unexpected behavior","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/nextjs/inline_script_id.rs#L1-L31","documentation":"Warning from oxlint rule `nextjs/inline-script-id`. Next.js registers inline `next/script` content under its `id` so the script is deduplicated and not re-executed during client-side navigation; without an `id` those guarantees break. Any `<Script>` that provides inline content via `dangerouslySetInnerHTML` must also declare an `id` attribute.","triggerScenarios":"A JSX element whose tag is the local name imported from `next/script` that sets `dangerouslySetInnerHTML={{ __html: ... }}` (inline content) and has no `id` attribute.","commonSituations":"Pasting an analytics or pixel snippet (GA4, GTM, Meta Pixel, Hotjar) into a Next.js page as inline `next/script`; converting a raw `<script>` tag to `next/script` while keeping the content but not adding an id; following older tutorials that omit `id`.","solutions":["Add a unique `id` attribute, e.g. `<Script id=\"ga4\" ...>`; ids must be unique across the whole app.","If the code comes from a third party, prefer an external script: `<Script src=\"https://...\" strategy=\"afterInteractive\" />` and drop the inline content.","Re-run oxlint (nextjs plugin) on the file to confirm the warning is gone."],"exampleFix":"// before\n<Script dangerouslySetInnerHTML={{ __html: `(function(){...})();` }} />\n\n// after\n<Script id=\"my-inline-script\">{`(function(){...})();`}</Script>","handlingStrategy":"validation","validationCode":"// CI gate: run the rule directly\n// npx oxlint -c .oxlintrc.json src   (.oxlintrc.json enables the nextjs plugin)\n// quick grep for inline scripts missing an id:\n// rg -U -n 'dangerouslySetInnerHTML' -g '*.tsx' src | rg -v 'id='","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat every inline `next/script` as needing a stable id named after its purpose (e.g. id=\"hotjar-init\").","Keep ids unique app-wide; reuse of an id makes Next.js dedupe the second script away.","Run oxlint with the nextjs plugin in CI so a missing id fails the build."],"tags":["nextjs","next-script","jsx","lint"],"backgroundTag":"lint-missing-attribute","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"}