From f9abdb6428a037a1ba1ced23bfe135eded020865 Mon Sep 17 00:00:00 2001 From: Elvin Seudieu Date: Thu, 23 Apr 2026 18:45:22 -0400 Subject: [PATCH 01/11] added compiler warning functionality for head warnings (untested) --- .../docs/98-reference/.generated/compile-warnings.md | 6 ++++++ .../svelte/messages/compile-warnings/template.md | 3 +++ .../phases/2-analyze/visitors/RegularElement.js | 6 +++++- packages/svelte/src/compiler/warnings.js | 12 ++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/documentation/docs/98-reference/.generated/compile-warnings.md b/documentation/docs/98-reference/.generated/compile-warnings.md index 7dfbe75888..c218867beb 100644 --- a/documentation/docs/98-reference/.generated/compile-warnings.md +++ b/documentation/docs/98-reference/.generated/compile-warnings.md @@ -697,6 +697,12 @@ Using `on:%name%` to listen to the %name% event is deprecated. Use the event att See [the migration guide](v5-migration-guide#Event-changes) for more info. +### head_in_component + +``` +A `` tag was detected in file `%filename%`, component `%component%`, at line %line%. This can lead to runtime errors. Did you mean to use ``? +``` + ### export_let_unused ``` diff --git a/packages/svelte/messages/compile-warnings/template.md b/packages/svelte/messages/compile-warnings/template.md index 3650e07b47..2a9fc8716f 100644 --- a/packages/svelte/messages/compile-warnings/template.md +++ b/packages/svelte/messages/compile-warnings/template.md @@ -83,6 +83,9 @@ In a future version of Svelte, self-closing tags may be upgraded from a warning See [the migration guide](v5-migration-guide#Event-changes) for more info. +## head_in_component +> A `` tag was detected in file `%filename%`, component `%component%`, at line %line%. This can lead to runtime errors. Did you mean to use ``? + ## node_invalid_placement_ssr > %message%. When rendering this component on the server, the resulting HTML will be modified by the browser (by moving, removing, or inserting elements), likely resulting in a `hydration_mismatch` warning diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js index bc65bd65db..17f1aed59c 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js @@ -17,7 +17,7 @@ import { check_element } from './shared/a11y/index.js'; import { validate_element } from './shared/element.js'; import { mark_subtree_dynamic } from './shared/fragment.js'; import { object } from '../../../utils/ast.js'; -import { runes } from '../../../state.js'; +import { component_name, filename, locator, runes } from '../../../state.js'; /** * @param {AST.RegularElement} node @@ -126,6 +126,10 @@ export function RegularElement(node, context) { w.component_name_lowercase(node, node.name); } + if (node.name === 'head' && !context.state.parent_element) { + w.head_in_component(node, filename, component_name, `${locator(node.start).line}`); + } + node.metadata.has_spread = node.attributes.some( (attribute) => attribute.type === 'SpreadAttribute' ); diff --git a/packages/svelte/src/compiler/warnings.js b/packages/svelte/src/compiler/warnings.js index 089cb1e118..27da0465ba 100644 --- a/packages/svelte/src/compiler/warnings.js +++ b/packages/svelte/src/compiler/warnings.js @@ -113,6 +113,7 @@ export const codes = [ 'element_implicitly_closed', 'element_invalid_self_closing_tag', 'event_directive_deprecated', + 'head_in_component', 'node_invalid_placement_ssr', 'script_context_deprecated', 'script_unknown_attribute', @@ -785,6 +786,17 @@ export function event_directive_deprecated(node, name) { w(node, 'event_directive_deprecated', `Using \`on:${name}\` to listen to the ${name} event is deprecated. Use the event attribute \`on${name}\` instead\nhttps://svelte.dev/e/event_directive_deprecated`); } +/** + * A `` tag was detected in file `%filename%`, component `%component%`, at line %line%. This can lead to runtime errors. Did you mean to use ``? + * @param {null | NodeLike} node + * @param {string} filename + * @param {string} component + * @param {string} line + */ +export function head_in_component(node, filename, component, line) { + w(node, 'head_in_component', `A \`\` tag was detected in file \`${filename}\`, component \`${component}\`, at line ${line}. This can lead to runtime errors. Did you mean to use \`\`?\nhttps://svelte.dev/e/head_in_component`); +} + /** * %message%. When rendering this component on the server, the resulting HTML will be modified by the browser (by moving, removing, or inserting elements), likely resulting in a `hydration_mismatch` warning * @param {null | NodeLike} node From a4905410df2a5a6abb6f73b3ede04d73f5564c39 Mon Sep 17 00:00:00 2001 From: 568cats <568cats@gmail.com> Date: Sat, 25 Apr 2026 18:31:45 -0400 Subject: [PATCH 02/11] Add test to ensure in components produces a warning --- .../samples/head-warning/_config.js | 18 ++++++++++++++++++ .../samples/head-warning/main.svelte | 3 +++ 2 files changed, 21 insertions(+) create mode 100644 packages/svelte/tests/runtime-browser/samples/head-warning/_config.js create mode 100644 packages/svelte/tests/runtime-browser/samples/head-warning/main.svelte diff --git a/packages/svelte/tests/runtime-browser/samples/head-warning/_config.js b/packages/svelte/tests/runtime-browser/samples/head-warning/_config.js new file mode 100644 index 0000000000..c916ba2d44 --- /dev/null +++ b/packages/svelte/tests/runtime-browser/samples/head-warning/_config.js @@ -0,0 +1,18 @@ +import { test } from '../../assert'; + +export default test({ + warnings: [{ + code: "head_in_component", + message: "A `` tag was detected in file `(unknown)`, component `_unknown_`, at line 1. This can lead to runtime errors. Did you mean to use ``?\nhttps://svelte.dev/e/head_in_component", + start: { + line: 1, + character: 0, + column: 0 + }, + end: { + line: 3, + character: 73, + column: 7 + } + }] +}); diff --git a/packages/svelte/tests/runtime-browser/samples/head-warning/main.svelte b/packages/svelte/tests/runtime-browser/samples/head-warning/main.svelte new file mode 100644 index 0000000000..faa18f91b6 --- /dev/null +++ b/packages/svelte/tests/runtime-browser/samples/head-warning/main.svelte @@ -0,0 +1,3 @@ + + + \ No newline at end of file From 0ba5dee5e223f0a5585ef283f76ec319d080a388 Mon Sep 17 00:00:00 2001 From: Elvin Seudieu Date: Tue, 28 Apr 2026 11:30:17 -0400 Subject: [PATCH 03/11] fixing lint issues --- .../.generated/compile-warnings.md | 6 ---- .../messages/compile-warnings/template.md | 3 -- .../samples/head-warning/_config.js | 31 ++++++++++--------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/documentation/docs/98-reference/.generated/compile-warnings.md b/documentation/docs/98-reference/.generated/compile-warnings.md index c218867beb..7dfbe75888 100644 --- a/documentation/docs/98-reference/.generated/compile-warnings.md +++ b/documentation/docs/98-reference/.generated/compile-warnings.md @@ -697,12 +697,6 @@ Using `on:%name%` to listen to the %name% event is deprecated. Use the event att See [the migration guide](v5-migration-guide#Event-changes) for more info. -### head_in_component - -``` -A `` tag was detected in file `%filename%`, component `%component%`, at line %line%. This can lead to runtime errors. Did you mean to use ``? -``` - ### export_let_unused ``` diff --git a/packages/svelte/messages/compile-warnings/template.md b/packages/svelte/messages/compile-warnings/template.md index 2a9fc8716f..3650e07b47 100644 --- a/packages/svelte/messages/compile-warnings/template.md +++ b/packages/svelte/messages/compile-warnings/template.md @@ -83,9 +83,6 @@ In a future version of Svelte, self-closing tags may be upgraded from a warning See [the migration guide](v5-migration-guide#Event-changes) for more info. -## head_in_component -> A `` tag was detected in file `%filename%`, component `%component%`, at line %line%. This can lead to runtime errors. Did you mean to use ``? - ## node_invalid_placement_ssr > %message%. When rendering this component on the server, the resulting HTML will be modified by the browser (by moving, removing, or inserting elements), likely resulting in a `hydration_mismatch` warning diff --git a/packages/svelte/tests/runtime-browser/samples/head-warning/_config.js b/packages/svelte/tests/runtime-browser/samples/head-warning/_config.js index c916ba2d44..fb62be1af2 100644 --- a/packages/svelte/tests/runtime-browser/samples/head-warning/_config.js +++ b/packages/svelte/tests/runtime-browser/samples/head-warning/_config.js @@ -1,18 +1,21 @@ import { test } from '../../assert'; export default test({ - warnings: [{ - code: "head_in_component", - message: "A `` tag was detected in file `(unknown)`, component `_unknown_`, at line 1. This can lead to runtime errors. Did you mean to use ``?\nhttps://svelte.dev/e/head_in_component", - start: { - line: 1, - character: 0, - column: 0 - }, - end: { - line: 3, - character: 73, - column: 7 - } - }] + warnings: [ + { + code: 'head_in_component', + message: + 'A `` tag was detected in file `(unknown)`, component `_unknown_`, at line 1. This can lead to runtime errors. Did you mean to use ``?\nhttps://svelte.dev/e/head_in_component', + start: { + line: 1, + character: 0, + column: 0 + }, + end: { + line: 3, + character: 73, + column: 7 + } + } + ] }); From 489b5fbb0dafabe2af7daa1e82803d00d511ecfd Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 29 Apr 2026 12:27:11 -0400 Subject: [PATCH 04/11] changeset --- .changeset/fresh-trains-doubt.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fresh-trains-doubt.md diff --git a/.changeset/fresh-trains-doubt.md b/.changeset/fresh-trains-doubt.md new file mode 100644 index 0000000000..69621d2208 --- /dev/null +++ b/.changeset/fresh-trains-doubt.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: warn when bare is used in a component From de2e09d59a7f59f6b45128f1be8dccd0adfb36af Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 29 Apr 2026 13:00:59 -0400 Subject: [PATCH 05/11] Update .changeset/fresh-trains-doubt.md Co-authored-by: Conduitry --- .changeset/fresh-trains-doubt.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/fresh-trains-doubt.md b/.changeset/fresh-trains-doubt.md index 69621d2208..5e68fd93fc 100644 --- a/.changeset/fresh-trains-doubt.md +++ b/.changeset/fresh-trains-doubt.md @@ -2,4 +2,4 @@ "svelte": patch --- -fix: warn when bare is used in a component +fix: warn when bare `` is used in a component From dae91eb65a45ce10d94a4f7ffdd78c8bb8961234 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 29 Apr 2026 13:12:48 -0400 Subject: [PATCH 06/11] fix message --- .../docs/98-reference/.generated/compile-warnings.md | 6 ++++++ packages/svelte/messages/compile-warnings/template.md | 4 ++++ .../phases/2-analyze/visitors/RegularElement.js | 4 ++-- packages/svelte/src/compiler/warnings.js | 10 ++++------ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/documentation/docs/98-reference/.generated/compile-warnings.md b/documentation/docs/98-reference/.generated/compile-warnings.md index 7dfbe75888..82678d0585 100644 --- a/documentation/docs/98-reference/.generated/compile-warnings.md +++ b/documentation/docs/98-reference/.generated/compile-warnings.md @@ -703,6 +703,12 @@ See [the migration guide](v5-migration-guide#Event-changes) for more info. Component has unused export property '%name%'. If it is for external reference only, please consider using `export const %name%` ``` +### head_in_component + +``` +Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/e/head_in_component) instead +``` + ### legacy_code ``` diff --git a/packages/svelte/messages/compile-warnings/template.md b/packages/svelte/messages/compile-warnings/template.md index 3650e07b47..8fe754ce56 100644 --- a/packages/svelte/messages/compile-warnings/template.md +++ b/packages/svelte/messages/compile-warnings/template.md @@ -83,6 +83,10 @@ In a future version of Svelte, self-closing tags may be upgraded from a warning See [the migration guide](v5-migration-guide#Event-changes) for more info. +## head_in_component + +> Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/e/head_in_component) instead + ## node_invalid_placement_ssr > %message%. When rendering this component on the server, the resulting HTML will be modified by the browser (by moving, removing, or inserting elements), likely resulting in a `hydration_mismatch` warning diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js index 17f1aed59c..bf65b106eb 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js @@ -17,7 +17,7 @@ import { check_element } from './shared/a11y/index.js'; import { validate_element } from './shared/element.js'; import { mark_subtree_dynamic } from './shared/fragment.js'; import { object } from '../../../utils/ast.js'; -import { component_name, filename, locator, runes } from '../../../state.js'; +import { component_name, filename, locate_node, locator, runes } from '../../../state.js'; /** * @param {AST.RegularElement} node @@ -127,7 +127,7 @@ export function RegularElement(node, context) { } if (node.name === 'head' && !context.state.parent_element) { - w.head_in_component(node, filename, component_name, `${locator(node.start).line}`); + w.head_in_component(node, locate_node(node)); } node.metadata.has_spread = node.attributes.some( diff --git a/packages/svelte/src/compiler/warnings.js b/packages/svelte/src/compiler/warnings.js index 27da0465ba..5e1ec79964 100644 --- a/packages/svelte/src/compiler/warnings.js +++ b/packages/svelte/src/compiler/warnings.js @@ -787,14 +787,12 @@ export function event_directive_deprecated(node, name) { } /** - * A `` tag was detected in file `%filename%`, component `%component%`, at line %line%. This can lead to runtime errors. Did you mean to use ``? + * Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/e/head_in_component) instead * @param {null | NodeLike} node - * @param {string} filename - * @param {string} component - * @param {string} line + * @param {string} location */ -export function head_in_component(node, filename, component, line) { - w(node, 'head_in_component', `A \`\` tag was detected in file \`${filename}\`, component \`${component}\`, at line ${line}. This can lead to runtime errors. Did you mean to use \`\`?\nhttps://svelte.dev/e/head_in_component`); +export function head_in_component(node, location) { + w(node, 'head_in_component', `Using \`\` (${location}) will likely lead to runtime errors. Use [\`\`](https://svelte.dev/e/head_in_component) instead\nhttps://svelte.dev/e/head_in_component`); } /** From d629fa1b7a3e6c1317977bcac4a072f1d385ceef Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 29 Apr 2026 13:15:03 -0400 Subject: [PATCH 07/11] fix test --- .../samples/head-warning/_config.js | 21 ------------------- .../samples/head-warning/main.svelte | 3 --- .../validator/samples/naked-head/input.svelte | 3 +++ .../samples/naked-head/warnings.json | 14 +++++++++++++ 4 files changed, 17 insertions(+), 24 deletions(-) delete mode 100644 packages/svelte/tests/runtime-browser/samples/head-warning/_config.js delete mode 100644 packages/svelte/tests/runtime-browser/samples/head-warning/main.svelte create mode 100644 packages/svelte/tests/validator/samples/naked-head/input.svelte create mode 100644 packages/svelte/tests/validator/samples/naked-head/warnings.json diff --git a/packages/svelte/tests/runtime-browser/samples/head-warning/_config.js b/packages/svelte/tests/runtime-browser/samples/head-warning/_config.js deleted file mode 100644 index fb62be1af2..0000000000 --- a/packages/svelte/tests/runtime-browser/samples/head-warning/_config.js +++ /dev/null @@ -1,21 +0,0 @@ -import { test } from '../../assert'; - -export default test({ - warnings: [ - { - code: 'head_in_component', - message: - 'A `` tag was detected in file `(unknown)`, component `_unknown_`, at line 1. This can lead to runtime errors. Did you mean to use ``?\nhttps://svelte.dev/e/head_in_component', - start: { - line: 1, - character: 0, - column: 0 - }, - end: { - line: 3, - character: 73, - column: 7 - } - } - ] -}); diff --git a/packages/svelte/tests/runtime-browser/samples/head-warning/main.svelte b/packages/svelte/tests/runtime-browser/samples/head-warning/main.svelte deleted file mode 100644 index faa18f91b6..0000000000 --- a/packages/svelte/tests/runtime-browser/samples/head-warning/main.svelte +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/packages/svelte/tests/validator/samples/naked-head/input.svelte b/packages/svelte/tests/validator/samples/naked-head/input.svelte new file mode 100644 index 0000000000..601ca34d65 --- /dev/null +++ b/packages/svelte/tests/validator/samples/naked-head/input.svelte @@ -0,0 +1,3 @@ + + + diff --git a/packages/svelte/tests/validator/samples/naked-head/warnings.json b/packages/svelte/tests/validator/samples/naked-head/warnings.json new file mode 100644 index 0000000000..4607baced0 --- /dev/null +++ b/packages/svelte/tests/validator/samples/naked-head/warnings.json @@ -0,0 +1,14 @@ +[ + { + "code": "head_in_component", + "message": "Using `` ((unknown):1:0) will likely lead to runtime errors. Use [``](https://svelte.dev/e/head_in_component) instead", + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 7 + } + } +] From d0c2048d1d25a18d78eb53afda287e6e579c2f8a Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 29 Apr 2026 14:15:11 -0400 Subject: [PATCH 08/11] lol oops --- .../docs/98-reference/.generated/compile-warnings.md | 2 +- packages/svelte/messages/compile-warnings/template.md | 2 +- packages/svelte/src/compiler/warnings.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/documentation/docs/98-reference/.generated/compile-warnings.md b/documentation/docs/98-reference/.generated/compile-warnings.md index 82678d0585..8d0aedbc07 100644 --- a/documentation/docs/98-reference/.generated/compile-warnings.md +++ b/documentation/docs/98-reference/.generated/compile-warnings.md @@ -706,7 +706,7 @@ Component has unused export property '%name%'. If it is for external reference o ### head_in_component ``` -Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/e/head_in_component) instead +Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/docs/svelte/svelte-head) instead ``` ### legacy_code diff --git a/packages/svelte/messages/compile-warnings/template.md b/packages/svelte/messages/compile-warnings/template.md index 8fe754ce56..1241b58d08 100644 --- a/packages/svelte/messages/compile-warnings/template.md +++ b/packages/svelte/messages/compile-warnings/template.md @@ -85,7 +85,7 @@ See [the migration guide](v5-migration-guide#Event-changes) for more info. ## head_in_component -> Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/e/head_in_component) instead +> Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/docs/svelte/svelte-head) instead ## node_invalid_placement_ssr diff --git a/packages/svelte/src/compiler/warnings.js b/packages/svelte/src/compiler/warnings.js index 5e1ec79964..c916d34d1a 100644 --- a/packages/svelte/src/compiler/warnings.js +++ b/packages/svelte/src/compiler/warnings.js @@ -787,12 +787,12 @@ export function event_directive_deprecated(node, name) { } /** - * Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/e/head_in_component) instead + * Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/docs/svelte/svelte-head) instead * @param {null | NodeLike} node * @param {string} location */ export function head_in_component(node, location) { - w(node, 'head_in_component', `Using \`\` (${location}) will likely lead to runtime errors. Use [\`\`](https://svelte.dev/e/head_in_component) instead\nhttps://svelte.dev/e/head_in_component`); + w(node, 'head_in_component', `Using \`\` (${location}) will likely lead to runtime errors. Use [\`\`](https://svelte.dev/docs/svelte/svelte-head) instead\nhttps://svelte.dev/e/head_in_component`); } /** From 98ccf31e97b83661798e40b8d53cf93606244e02 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 29 Apr 2026 14:17:23 -0400 Subject: [PATCH 09/11] final deslopification (hopefully) --- .../svelte/tests/validator/samples/naked-head/warnings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/tests/validator/samples/naked-head/warnings.json b/packages/svelte/tests/validator/samples/naked-head/warnings.json index 4607baced0..bfbd5ce0f8 100644 --- a/packages/svelte/tests/validator/samples/naked-head/warnings.json +++ b/packages/svelte/tests/validator/samples/naked-head/warnings.json @@ -1,7 +1,7 @@ [ { "code": "head_in_component", - "message": "Using `` ((unknown):1:0) will likely lead to runtime errors. Use [``](https://svelte.dev/e/head_in_component) instead", + "message": "Using `` ((unknown):1:0) will likely lead to runtime errors. Use [``](https://svelte.dev/docs/svelte/svelte-head) instead", "start": { "line": 1, "column": 0 From 9dc0f484e693c4a0d38774c040206f83f423b961 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 29 Apr 2026 14:19:59 -0400 Subject: [PATCH 10/11] actually no, not final. head_in_component makes no sense. renamed it. man i hate slop --- .../docs/98-reference/.generated/compile-warnings.md | 2 +- packages/svelte/messages/compile-warnings/template.md | 2 +- .../compiler/phases/2-analyze/visitors/RegularElement.js | 2 +- packages/svelte/src/compiler/warnings.js | 8 ++++---- .../tests/validator/samples/naked-head/warnings.json | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/documentation/docs/98-reference/.generated/compile-warnings.md b/documentation/docs/98-reference/.generated/compile-warnings.md index 8d0aedbc07..d37d297526 100644 --- a/documentation/docs/98-reference/.generated/compile-warnings.md +++ b/documentation/docs/98-reference/.generated/compile-warnings.md @@ -703,7 +703,7 @@ See [the migration guide](v5-migration-guide#Event-changes) for more info. Component has unused export property '%name%'. If it is for external reference only, please consider using `export const %name%` ``` -### head_in_component +### unexpected_head ``` Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/docs/svelte/svelte-head) instead diff --git a/packages/svelte/messages/compile-warnings/template.md b/packages/svelte/messages/compile-warnings/template.md index 1241b58d08..cae0f1c38c 100644 --- a/packages/svelte/messages/compile-warnings/template.md +++ b/packages/svelte/messages/compile-warnings/template.md @@ -83,7 +83,7 @@ In a future version of Svelte, self-closing tags may be upgraded from a warning See [the migration guide](v5-migration-guide#Event-changes) for more info. -## head_in_component +## unexpected_head > Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/docs/svelte/svelte-head) instead diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js index bf65b106eb..d213f5e43a 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js @@ -127,7 +127,7 @@ export function RegularElement(node, context) { } if (node.name === 'head' && !context.state.parent_element) { - w.head_in_component(node, locate_node(node)); + w.unexpected_head(node, locate_node(node)); } node.metadata.has_spread = node.attributes.some( diff --git a/packages/svelte/src/compiler/warnings.js b/packages/svelte/src/compiler/warnings.js index c916d34d1a..7959b7d211 100644 --- a/packages/svelte/src/compiler/warnings.js +++ b/packages/svelte/src/compiler/warnings.js @@ -113,7 +113,7 @@ export const codes = [ 'element_implicitly_closed', 'element_invalid_self_closing_tag', 'event_directive_deprecated', - 'head_in_component', + 'unexpected_head', 'node_invalid_placement_ssr', 'script_context_deprecated', 'script_unknown_attribute', @@ -791,8 +791,8 @@ export function event_directive_deprecated(node, name) { * @param {null | NodeLike} node * @param {string} location */ -export function head_in_component(node, location) { - w(node, 'head_in_component', `Using \`\` (${location}) will likely lead to runtime errors. Use [\`\`](https://svelte.dev/docs/svelte/svelte-head) instead\nhttps://svelte.dev/e/head_in_component`); +export function unexpected_head(node, location) { + w(node, 'unexpected_head', `Using \`\` (${location}) will likely lead to runtime errors. Use [\`\`](https://svelte.dev/docs/svelte/svelte-head) instead\nhttps://svelte.dev/e/unexpected_head`); } /** @@ -852,4 +852,4 @@ export function svelte_element_invalid_this(node) { */ export function svelte_self_deprecated(node, name, basename) { w(node, 'svelte_self_deprecated', `\`\` is deprecated — use self-imports (e.g. \`import ${name} from './${basename}'\`) instead\nhttps://svelte.dev/e/svelte_self_deprecated`); -} \ No newline at end of file +} diff --git a/packages/svelte/tests/validator/samples/naked-head/warnings.json b/packages/svelte/tests/validator/samples/naked-head/warnings.json index bfbd5ce0f8..9820233a88 100644 --- a/packages/svelte/tests/validator/samples/naked-head/warnings.json +++ b/packages/svelte/tests/validator/samples/naked-head/warnings.json @@ -1,6 +1,6 @@ [ { - "code": "head_in_component", + "code": "unexpected_head", "message": "Using `` ((unknown):1:0) will likely lead to runtime errors. Use [``](https://svelte.dev/docs/svelte/svelte-head) instead", "start": { "line": 1, From 23865447c4a8ca2e5cbfc6cf37f34ae3ae3c2a4e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 29 Apr 2026 14:21:19 -0400 Subject: [PATCH 11/11] lint --- .../.generated/compile-warnings.md | 12 +++++----- .../messages/compile-warnings/template.md | 8 +++---- packages/svelte/src/compiler/warnings.js | 22 +++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/documentation/docs/98-reference/.generated/compile-warnings.md b/documentation/docs/98-reference/.generated/compile-warnings.md index d37d297526..e32931d097 100644 --- a/documentation/docs/98-reference/.generated/compile-warnings.md +++ b/documentation/docs/98-reference/.generated/compile-warnings.md @@ -703,12 +703,6 @@ See [the migration guide](v5-migration-guide#Event-changes) for more info. Component has unused export property '%name%'. If it is for external reference only, please consider using `export const %name%` ``` -### unexpected_head - -``` -Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/docs/svelte/svelte-head) instead -``` - ### legacy_code ``` @@ -988,6 +982,12 @@ A derived value may be used in other contexts: See [the note in the docs](legacy-svelte-self) for more info. +### unexpected_head + +``` +Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/docs/svelte/svelte-head) instead +``` + ### unknown_code ``` diff --git a/packages/svelte/messages/compile-warnings/template.md b/packages/svelte/messages/compile-warnings/template.md index cae0f1c38c..857b409241 100644 --- a/packages/svelte/messages/compile-warnings/template.md +++ b/packages/svelte/messages/compile-warnings/template.md @@ -83,10 +83,6 @@ In a future version of Svelte, self-closing tags may be upgraded from a warning See [the migration guide](v5-migration-guide#Event-changes) for more info. -## unexpected_head - -> Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/docs/svelte/svelte-head) instead - ## node_invalid_placement_ssr > %message%. When rendering this component on the server, the resulting HTML will be modified by the browser (by moving, removing, or inserting elements), likely resulting in a `hydration_mismatch` warning @@ -163,3 +159,7 @@ A derived value may be used in other contexts: > `` is deprecated — use self-imports (e.g. `import %name% from './%basename%'`) instead See [the note in the docs](legacy-svelte-self) for more info. + +## unexpected_head + +> Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/docs/svelte/svelte-head) instead diff --git a/packages/svelte/src/compiler/warnings.js b/packages/svelte/src/compiler/warnings.js index 7959b7d211..04bd55592a 100644 --- a/packages/svelte/src/compiler/warnings.js +++ b/packages/svelte/src/compiler/warnings.js @@ -113,14 +113,14 @@ export const codes = [ 'element_implicitly_closed', 'element_invalid_self_closing_tag', 'event_directive_deprecated', - 'unexpected_head', 'node_invalid_placement_ssr', 'script_context_deprecated', 'script_unknown_attribute', 'slot_element_deprecated', 'svelte_component_deprecated', 'svelte_element_invalid_this', - 'svelte_self_deprecated' + 'svelte_self_deprecated', + 'unexpected_head' ]; /** @@ -786,15 +786,6 @@ export function event_directive_deprecated(node, name) { w(node, 'event_directive_deprecated', `Using \`on:${name}\` to listen to the ${name} event is deprecated. Use the event attribute \`on${name}\` instead\nhttps://svelte.dev/e/event_directive_deprecated`); } -/** - * Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/docs/svelte/svelte-head) instead - * @param {null | NodeLike} node - * @param {string} location - */ -export function unexpected_head(node, location) { - w(node, 'unexpected_head', `Using \`\` (${location}) will likely lead to runtime errors. Use [\`\`](https://svelte.dev/docs/svelte/svelte-head) instead\nhttps://svelte.dev/e/unexpected_head`); -} - /** * %message%. When rendering this component on the server, the resulting HTML will be modified by the browser (by moving, removing, or inserting elements), likely resulting in a `hydration_mismatch` warning * @param {null | NodeLike} node @@ -853,3 +844,12 @@ export function svelte_element_invalid_this(node) { export function svelte_self_deprecated(node, name, basename) { w(node, 'svelte_self_deprecated', `\`\` is deprecated — use self-imports (e.g. \`import ${name} from './${basename}'\`) instead\nhttps://svelte.dev/e/svelte_self_deprecated`); } + +/** + * Using `` (%location%) will likely lead to runtime errors. Use [``](https://svelte.dev/docs/svelte/svelte-head) instead + * @param {null | NodeLike} node + * @param {string} location + */ +export function unexpected_head(node, location) { + w(node, 'unexpected_head', `Using \`\` (${location}) will likely lead to runtime errors. Use [\`\`](https://svelte.dev/docs/svelte/svelte-head) instead\nhttps://svelte.dev/e/unexpected_head`); +} \ No newline at end of file