diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 336e0ff46c..8ec549b561 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -199,7 +199,7 @@ export function claim_element(nodes, name, attributes, svg) { return node; } else { // Ignore hydration errors caused by empty text nodes - if (node.nodeType !== 3 || !node.data.match(/\s+/)) { + if (node.nodeType !== 3 || (node.data !== ' ' && node.data !== '')) { console.error(`Hydration error: Expected node "${name}" but found`, node); } detach(node); @@ -211,15 +211,19 @@ export function claim_element(nodes, name, attributes, svg) { export function claim_text(nodes, data) { const node = nodes[0]; + if (node) { if (node.nodeType === 3) { node.data = '' + data; return nodes.shift(); - } else if (!data.match(/\s+/)) { - console.error(`Hydration error: Expected text node "${data}" but found`, node); - detach(node); + } else if (data !== ' ' && data !== '') { + console.error( + `Hydration error: Expected text node "${data}" but found`, + node + ); } } + return text(data); }