check for any error and better node removal

fix-15337
7nik 1 month ago
parent 62bf167f53
commit 565ae54099

@ -62,20 +62,25 @@ export function head(render_fn) {
check_end(); check_end();
} catch (error) { } catch (error) {
// Remount only this svelte:head // Remount only this svelte:head
if (was_hydrating && head_anchor && error === HYDRATION_ERROR) { if (was_hydrating && head_anchor != null) {
hydration_mismatch();
// Here head_anchor is the node next after HYDRATION_START // Here head_anchor is the node next after HYDRATION_START
/** @type {Node | null} */ /** @type {Node | null} */
let node = head_anchor.previousSibling; var node = head_anchor.previousSibling;
// Remove nodes that failed to hydrate // Remove nodes that failed to hydrate
var depth = 0;
while (node !== null) { while (node !== null) {
const removed = node; var prev = /** @type {TemplateNode} */ (node);
node = get_next_sibling(node); node = get_next_sibling(node);
document.head.removeChild(removed); prev.remove();
if ( if (prev.nodeType === COMMENT_NODE) {
removed.nodeType === COMMENT_NODE && var data = /** @type {Comment} */ (prev).data;
/** @type {Comment} */ (removed).data === HYDRATION_END if (data === HYDRATION_END) {
) { depth -= 1;
break; if (depth === 0) break;
} else if (data === HYDRATION_START) {
depth += 1;
}
} }
} }
// Setup hydration for the next svelte:head // Setup hydration for the next svelte:head

Loading…
Cancel
Save