Skip to content

Commit 66de9a0

Browse files
authored
Revert "chore: improve ssr parent validation (#13158)"
This reverts commit 0332abb.
1 parent 501f415 commit 66de9a0

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

.changeset/strange-trains-destroy.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/svelte/src/html-tree-validation.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,23 +162,21 @@ export function is_tag_valid_with_ancestor(tag, ancestors) {
162162
* Returns false if the tag is not allowed inside the parent tag such that it will result
163163
* in the browser repairing the HTML, which will likely result in an error during hydration.
164164
* @param {string} tag
165-
* @param {string | null} parent_tag
165+
* @param {string} parent_tag
166166
* @returns {boolean}
167167
*/
168168
export function is_tag_valid_with_parent(tag, parent_tag) {
169-
if (parent_tag !== null) {
170-
const disallowed = disallowed_children[parent_tag];
169+
const disallowed = disallowed_children[parent_tag];
171170

172-
if (disallowed) {
173-
if ('direct' in disallowed && disallowed.direct.includes(tag)) {
174-
return false;
175-
}
176-
if ('descendant' in disallowed && disallowed.descendant.includes(tag)) {
177-
return false;
178-
}
179-
if ('only' in disallowed && disallowed.only) {
180-
return disallowed.only.includes(tag);
181-
}
171+
if (disallowed) {
172+
if ('direct' in disallowed && disallowed.direct.includes(tag)) {
173+
return false;
174+
}
175+
if ('descendant' in disallowed && disallowed.descendant.includes(tag)) {
176+
return false;
177+
}
178+
if ('only' in disallowed && disallowed.only) {
179+
return disallowed.only.includes(tag);
182180
}
183181
}
184182

packages/svelte/src/internal/server/dev.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ function stringify(element) {
3434

3535
/**
3636
* @param {Payload} payload
37-
* @param {Element | null} parent
37+
* @param {Element} parent
3838
* @param {Element} child
3939
*/
4040
function print_error(payload, parent, child) {
4141
var message =
42-
(parent === null
43-
? `node_invalid_placement_ssr: ${stringify(child)} needs a valid parent element\n\n`
44-
: `node_invalid_placement_ssr: ${stringify(parent)} cannot contain ${stringify(child)}\n\n`) +
42+
`node_invalid_placement_ssr: ${stringify(parent)} cannot contain ${stringify(child)}\n\n` +
4543
'This can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.';
4644

4745
if ((seen ??= new Set()).has(message)) return;
@@ -81,8 +79,6 @@ export function push_element(payload, tag, line, column) {
8179
}
8280
ancestor = ancestor.parent;
8381
}
84-
} else if (!is_tag_valid_with_parent(tag, null)) {
85-
print_error(payload, null, child);
8682
}
8783

8884
parent = child;

0 commit comments

Comments
 (0)