Revert "chore: improve ssr parent validation (#13158)"

This reverts commit 0332abbd83.
revert-13158-valid-ssr
Rich Harris 4 months ago committed by GitHub
parent 501f415190
commit 66de9a0481
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,5 +0,0 @@
---
'svelte': patch
---
chore: improve ssr parent validation

@ -162,11 +162,10 @@ export function is_tag_valid_with_ancestor(tag, ancestors) {
* Returns false if the tag is not allowed inside the parent tag such that it will result * Returns false if the tag is not allowed inside the parent tag such that it will result
* in the browser repairing the HTML, which will likely result in an error during hydration. * in the browser repairing the HTML, which will likely result in an error during hydration.
* @param {string} tag * @param {string} tag
* @param {string | null} parent_tag * @param {string} parent_tag
* @returns {boolean} * @returns {boolean}
*/ */
export function is_tag_valid_with_parent(tag, parent_tag) { export function is_tag_valid_with_parent(tag, parent_tag) {
if (parent_tag !== null) {
const disallowed = disallowed_children[parent_tag]; const disallowed = disallowed_children[parent_tag];
if (disallowed) { if (disallowed) {
@ -180,7 +179,6 @@ export function is_tag_valid_with_parent(tag, parent_tag) {
return disallowed.only.includes(tag); return disallowed.only.includes(tag);
} }
} }
}
switch (tag) { switch (tag) {
case 'body': case 'body':

@ -34,14 +34,12 @@ function stringify(element) {
/** /**
* @param {Payload} payload * @param {Payload} payload
* @param {Element | null} parent * @param {Element} parent
* @param {Element} child * @param {Element} child
*/ */
function print_error(payload, parent, child) { function print_error(payload, parent, child) {
var message = var message =
(parent === null `node_invalid_placement_ssr: ${stringify(parent)} cannot contain ${stringify(child)}\n\n` +
? `node_invalid_placement_ssr: ${stringify(child)} needs a valid parent element\n\n`
: `node_invalid_placement_ssr: ${stringify(parent)} cannot contain ${stringify(child)}\n\n`) +
'This can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.'; 'This can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.';
if ((seen ??= new Set()).has(message)) return; if ((seen ??= new Set()).has(message)) return;
@ -81,8 +79,6 @@ export function push_element(payload, tag, line, column) {
} }
ancestor = ancestor.parent; ancestor = ancestor.parent;
} }
} else if (!is_tag_valid_with_parent(tag, null)) {
print_error(payload, null, child);
} }
parent = child; parent = child;

Loading…
Cancel
Save