Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chilly-bats-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: hydrate each blocks inside element correctly
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ export function process_children(nodes, initial, is_element, context) {

if (is_static_element(node, context.state)) {
skipped += 1;
} else if (node.type === 'EachBlock' && nodes.length === 1 && is_element) {
} else if (
node.type === 'EachBlock' &&
nodes.length === 1 &&
is_element &&
// 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
// TODO switch this around and instead optimize for elements with a single block child and not require extra comments (neither for async nor normally)
!(node.body.metadata.has_await || node.metadata.expression.has_await)
) {
node.metadata.is_controlled = true;
} else {
const id = flush_node(false, node.type === 'RegularElement' ? node.name : 'node');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { tick } from 'svelte';
import { test } from '../../test';

export default test({
mode: ['async-server', 'hydrate', 'client'],
ssrHtml: `<ul><li>1</li></ul> <button>add</button>`,

async test({ assert, target }) {
await tick();
const [add] = target.querySelectorAll('button');

add.click();
await tick();
assert.htmlEqual(target.innerHTML, `<ul><li>1</li><li>2</li></ul> <button>add</button>`);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script>
let array = $state(Promise.resolve([1]));
</script>

<ul>
{#each await array as item}
<li>{item}</li>
{/each}
</ul>

<button onclick={() => array = Promise.resolve([1, 2])}>add</button>
Loading