Skip to content

Commit 669f6b4

Browse files
authored
fix: prevent hydration error on async {@html ...} (#17999)
Fixes #17981
1 parent 54ba176 commit 669f6b4

4 files changed

Lines changed: 30 additions & 3 deletions

File tree

.changeset/four-beers-like.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: prevent hydration error on async `{@html ...}`

packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,14 @@ export function process_children(nodes, initial, is_element, context) {
101101
if (is_static_element(node)) {
102102
skipped += 1;
103103
} else if (
104-
node.type === 'EachBlock' &&
104+
(node.type === 'EachBlock' || node.type === 'HtmlTag') &&
105105
nodes.length === 1 &&
106106
is_element &&
107107
// In case it's wrapped in async the async logic will want to skip sibling nodes up until the end, hence we cannot make this controlled
108108
// TODO switch this around and instead optimize for elements with a single block child and not require extra comments (neither for async nor normally)
109109
!node.metadata.expression.is_async()
110110
) {
111111
node.metadata.is_controlled = true;
112-
} else if (node.type === 'HtmlTag' && nodes.length === 1 && is_element) {
113-
node.metadata.is_controlled = true;
114112
} else {
115113
const id = flush_node(
116114
false,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { tick } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
mode: ['hydrate'],
6+
async test({ assert, target }) {
7+
await tick();
8+
assert.htmlEqual(target.innerHTML, `<div><div><p>first test</p></div> other test</div>`);
9+
}
10+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script>
2+
function firstTest() {
3+
return Promise.resolve('<p>first test</p>');
4+
}
5+
6+
function otherTest() {
7+
return Promise.resolve('other test');
8+
}
9+
</script>
10+
11+
<div>
12+
<div>{@html await firstTest()}</div>
13+
{await otherTest()}
14+
</div>

0 commit comments

Comments
 (0)