From bbc931e774035b3613ab1822230905738430bc1d Mon Sep 17 00:00:00 2001 From: Bao Nguyen Date: Tue, 1 Sep 2026 17:07:24 +0700 Subject: [PATCH] fix: report invalid placement for all elements that auto-close a `

` --- .changeset/violet-berries-repair.md | 5 + packages/svelte/src/html-tree-validation.js | 9 ++ .../invalid-node-placement-9/input.svelte | 13 +++ .../invalid-node-placement-9/warnings.json | 98 +++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 .changeset/violet-berries-repair.md create mode 100644 packages/svelte/tests/validator/samples/invalid-node-placement-9/input.svelte create mode 100644 packages/svelte/tests/validator/samples/invalid-node-placement-9/warnings.json diff --git a/.changeset/violet-berries-repair.md b/.changeset/violet-berries-repair.md new file mode 100644 index 0000000000..b42ce3841e --- /dev/null +++ b/.changeset/violet-berries-repair.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: report invalid placement for all elements that auto-close a `

` diff --git a/packages/svelte/src/html-tree-validation.js b/packages/svelte/src/html-tree-validation.js index d05cb81a71..53c24cec0b 100644 --- a/packages/svelte/src/html-tree-validation.js +++ b/packages/svelte/src/html-tree-validation.js @@ -10,15 +10,22 @@ const autoclosing_children = { // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dt#technical_summary dt: { descendant: ['dt', 'dd'], reset_by: ['dl'] }, dd: { descendant: ['dt', 'dd'], reset_by: ['dl'] }, + // https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody p: { descendant: [ 'address', 'article', 'aside', 'blockquote', + 'center', + 'details', + 'dialog', + 'dir', 'div', 'dl', 'fieldset', + 'figcaption', + 'figure', 'footer', 'form', 'h1', @@ -36,7 +43,9 @@ const autoclosing_children = { 'ol', 'p', 'pre', + 'search', 'section', + 'summary', 'table', 'ul' ] diff --git a/packages/svelte/tests/validator/samples/invalid-node-placement-9/input.svelte b/packages/svelte/tests/validator/samples/invalid-node-placement-9/input.svelte new file mode 100644 index 0000000000..e816e07de8 --- /dev/null +++ b/packages/svelte/tests/validator/samples/invalid-node-placement-9/input.svelte @@ -0,0 +1,13 @@ +

+ {#if foo} +

a
+
b
+ c + d +
e
+ f + g + +
h
+ {/if} +

diff --git a/packages/svelte/tests/validator/samples/invalid-node-placement-9/warnings.json b/packages/svelte/tests/validator/samples/invalid-node-placement-9/warnings.json new file mode 100644 index 0000000000..984bc5de3e --- /dev/null +++ b/packages/svelte/tests/validator/samples/invalid-node-placement-9/warnings.json @@ -0,0 +1,98 @@ +[ + { + "code": "node_invalid_placement_ssr", + "message": "`
` cannot be a child of `

`. 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", + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 20 + } + }, + { + "code": "node_invalid_placement_ssr", + "message": "`

` cannot be a child of `

`. 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", + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 22 + } + }, + { + "code": "node_invalid_placement_ssr", + "message": "`

` cannot be a child of `

`. 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", + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 20 + } + }, + { + "code": "node_invalid_placement_ssr", + "message": "`

` cannot be a child of `

`. 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", + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 14 + } + }, + { + "code": "node_invalid_placement_ssr", + "message": "`

` cannot be a child of `

`. 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", + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 20 + } + }, + { + "code": "node_invalid_placement_ssr", + "message": "`` cannot be a child of `

`. 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", + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 20 + } + }, + { + "code": "node_invalid_placement_ssr", + "message": "`

` cannot be a child of `

`. 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", + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 22 + } + }, + { + "code": "node_invalid_placement_ssr", + "message": "`

` cannot be a child of `

`. 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", + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 28 + } + } +]