fix await blocks

For some reason await blocks render html whitespace and
their custom hydration error handling seems to depend
on hydrating text nodes.
pull/16243/head
Jan Vogt 2 months ago
parent a28a11edda
commit e9bd78259f

@ -36,7 +36,7 @@ const CATCH = 2;
*/
export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
if (hydrating) {
hydrate_next();
hydrate_next(true);
}
var anchor = node;

@ -40,9 +40,25 @@ export function set_hydrate_node(node) {
return (hydrate_node = node);
}
export function hydrate_next() {
/**
* Moove to the next node to be hydrated. Empty text nodes will be skipped,
* unless `allow_text` is set to true.
*
* Skipping whitespace helps to sucessful hydrate even if some middleware added
* arbitrary whitespace into the html. This was at least twice an issue:
*
* - https://github.com/sveltejs/svelte/issues/15819
* - https://github.com/sveltejs/svelte/issues/16242
*
* Removing empty text nodes should be finde, as required text nodes will be
* added on demand. Doing so is necessary because an empty text on the server
* side will result in a missing text nodes as well.
*
* @param {boolean} allow_text
*/
export function hydrate_next(allow_text = false) {
var node = set_hydrate_node(/** @type {TemplateNode} */(get_next_sibling(hydrate_node)));
while (hydrate_node.nodeType === TEXT_NODE && !hydrate_node.nodeValue?.trim()) {
while (!allow_text && node.nodeType === TEXT_NODE && !node.nodeValue?.trim()) {
var next_sibling = get_next_sibling(hydrate_node)
hydrate_node.parentElement?.removeChild(hydrate_node)
node = set_hydrate_node(/** @type {TemplateNode} */(next_sibling))

Loading…
Cancel
Save