diff --git a/errors/manifest.json b/errors/manifest.json index 930a16a147dbc..4b0e39c5251d8 100644 --- a/errors/manifest.json +++ b/errors/manifest.json @@ -481,8 +481,12 @@ "path": "/errors/no-script-in-document-page.md" }, { - "title": "script-in-head-component", - "path": "/errors/no-script-in-head-component.md" + "title": "script-component-in-head-component", + "path": "/errors/no-script-component-in-head-component.md" + }, + { + "title": "script-tags-in-head-component", + "path": "/errors/no-script-tags-in-head-component.md" }, { "title": "max-custom-routes-reached", diff --git a/errors/no-script-in-head-component.md b/errors/no-script-component-in-head-component.md similarity index 100% rename from errors/no-script-in-head-component.md rename to errors/no-script-component-in-head-component.md diff --git a/errors/no-script-tags-in-head-component.md b/errors/no-script-tags-in-head-component.md new file mode 100644 index 0000000000000..278ab907b8926 --- /dev/null +++ b/errors/no-script-tags-in-head-component.md @@ -0,0 +1,36 @@ +# No Script Tags In Head Component + +### Why This Error Occurred + +A ` +
Home Page
+ + ) +} + +export default Home +``` + +### Useful Links + +- [Script component docs](https://nextjs.org/docs/basic-features/script/) diff --git a/packages/eslint-plugin-next/lib/index.js b/packages/eslint-plugin-next/lib/index.js index c5ef6936c09a7..295978b671b6f 100644 --- a/packages/eslint-plugin-next/lib/index.js +++ b/packages/eslint-plugin-next/lib/index.js @@ -14,7 +14,7 @@ module.exports = { 'no-document-import-in-page': require('./rules/no-document-import-in-page'), 'no-head-import-in-document': require('./rules/no-head-import-in-document'), 'no-script-in-document': require('./rules/no-script-in-document'), - 'no-script-in-head': require('./rules/no-script-in-head'), + 'no-script-component-in-head': require('./rules/no-script-component-in-head'), 'no-server-import-in-page': require('./rules/no-server-import-in-page'), 'no-typos': require('./rules/no-typos'), 'no-duplicate-head': require('./rules/no-duplicate-head'), @@ -40,7 +40,7 @@ module.exports = { '@next/next/no-document-import-in-page': 2, '@next/next/no-head-import-in-document': 2, '@next/next/no-script-in-document': 2, - '@next/next/no-script-in-head': 2, + '@next/next/no-script-component-in-head': 2, '@next/next/no-server-import-in-page': 2, '@next/next/no-typos': 1, '@next/next/no-duplicate-head': 2, diff --git a/packages/eslint-plugin-next/lib/rules/no-script-in-head.js b/packages/eslint-plugin-next/lib/rules/no-script-component-in-head.js similarity index 87% rename from packages/eslint-plugin-next/lib/rules/no-script-in-head.js rename to packages/eslint-plugin-next/lib/rules/no-script-component-in-head.js index 499832796c89d..90e0fbe4bc8c4 100644 --- a/packages/eslint-plugin-next/lib/rules/no-script-in-head.js +++ b/packages/eslint-plugin-next/lib/rules/no-script-component-in-head.js @@ -3,7 +3,7 @@ module.exports = { docs: { description: 'Disallow using next/script inside the next/head component', recommended: true, - url: 'https://nextjs.org/docs/messages/no-script-in-head-component', + url: 'https://nextjs.org/docs/messages/no-script-component-in-head-component', }, }, create: function (context) { @@ -43,7 +43,7 @@ module.exports = { context.report({ node, message: - "next/script shouldn't be used inside next/head. See: https://nextjs.org/docs/messages/no-script-in-head-component", + "next/script shouldn't be used inside next/head. See: https://nextjs.org/docs/messages/no-script-component-in-head-component", }) } }, diff --git a/packages/next/shared/lib/head.tsx b/packages/next/shared/lib/head.tsx index 64c7764edfd1d..25bbac4b8711e 100644 --- a/packages/next/shared/lib/head.tsx +++ b/packages/next/shared/lib/head.tsx @@ -161,6 +161,12 @@ function reduceComponents( return React.cloneElement(c, newProps) } } + // TODO(kara): warn for stylesheets as well as scripts + if (process.env.NODE_ENV === 'development' && c.type === 'script') { + console.warn( + `Do not add