Skip to content

Commit 3d80d6a

Browse files
author
Jan Vogt
committed
fix await blocks
For some reason await blocks render html whitespace and their custom hydration error handling seems to depend on hydrating text nodes.
1 parent 025af04 commit 3d80d6a

File tree

5 files changed

+86
-3
lines changed

5 files changed

+86
-3
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

flake.lock

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
inputs = { utils.url = "github:numtide/flake-utils"; };
3+
outputs = { self, nixpkgs, utils }:
4+
utils.lib.eachDefaultSystem (system:
5+
let pkgs = nixpkgs.legacyPackages.${system};
6+
in {
7+
devShell = pkgs.mkShell { buildInputs = with pkgs; [ nodejs pnpm ]; };
8+
});
9+
}

packages/svelte/src/internal/client/dom/blocks/await.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const CATCH = 2;
3636
*/
3737
export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
3838
if (hydrating) {
39-
hydrate_next();
39+
hydrate_next(true);
4040
}
4141

4242
var anchor = node;

packages/svelte/src/internal/client/dom/hydration.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,25 @@ export function set_hydrate_node(node) {
4040
return (hydrate_node = node);
4141
}
4242

43-
export function hydrate_next() {
43+
/**
44+
* Moove to the next node to be hydrated. Empty text nodes will be skipped,
45+
* unless `allow_text` is set to true.
46+
*
47+
* Skipping whitespace helps to sucessful hydrate even if some middleware added
48+
* arbitrary whitespace into the html. This was at least twice an issue:
49+
*
50+
* - https://github.com/sveltejs/svelte/issues/15819
51+
* - https://github.com/sveltejs/svelte/issues/15819
52+
*
53+
* Removing empty text nodes should be finde, as required text nodes will be
54+
* added on demand. Doing so is necessary because an empty text on the server
55+
* side will result in a missing text nodes as well.
56+
*
57+
* @param {boolean} allow_text
58+
*/
59+
export function hydrate_next(allow_text = false) {
4460
var node = set_hydrate_node(/** @type {TemplateNode} */(get_next_sibling(hydrate_node)));
45-
while (hydrate_node.nodeType === TEXT_NODE && !hydrate_node.nodeValue?.trim()) {
61+
while (!allow_text && node.nodeType === TEXT_NODE && !node.nodeValue?.trim()) {
4662
var next_sibling = get_next_sibling(hydrate_node)
4763
hydrate_node.parentElement?.removeChild(hydrate_node)
4864
node = set_hydrate_node(/** @type {TemplateNode} */(next_sibling))

0 commit comments

Comments
 (0)