From dd0a07b062c1e10a2af9483be1dbd4ee54c64093 Mon Sep 17 00:00:00 2001 From: Jonatan Svennberg Date: Sat, 31 Oct 2020 00:32:07 +0100 Subject: [PATCH] Make claim_text less greedy Avoids hydration errors caused by whitespace diffs --- src/runtime/internal/dom.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 903553ca4c..336e0ff46c 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -210,12 +210,12 @@ export function claim_element(nodes, name, attributes, svg) { } export function claim_text(nodes, data) { - const node = nodes.shift(); + const node = nodes[0]; if (node) { if (node.nodeType === 3) { node.data = '' + data; - return node; - } else { + return nodes.shift(); + } else if (!data.match(/\s+/)) { console.error(`Hydration error: Expected text node "${data}" but found`, node); detach(node); }