Skip to content

Commit be9b0a2

Browse files
fix: repair each block length even without an else (#12098)
* fix: repair each block length even without an else * chore: add changeset * simplify --------- Co-authored-by: Rich Harris <[email protected]>
1 parent 6a3e293 commit be9b0a2

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

.changeset/happy-lobsters-lick.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: repair each block length even without an else

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export function each(anchor, flags, get_collection, get_key, render_fn, fallback
151151
if (hydrating) {
152152
var is_else = /** @type {Comment} */ (anchor).data === HYDRATION_END_ELSE;
153153

154-
if (is_else !== (length === 0)) {
154+
if (is_else !== (length === 0) || hydrate_start === undefined) {
155155
// hydration mismatch — remove the server-rendered DOM and start over
156156
remove(hydrate_nodes);
157157
set_hydrating(false);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { assert_ok, test } from '../../test';
2+
3+
export default test({
4+
server_props: {
5+
items: []
6+
},
7+
8+
props: {
9+
items: [{ name: 'a' }]
10+
},
11+
12+
snapshot(target) {
13+
const ul = target.querySelector('ul');
14+
assert_ok(ul);
15+
16+
return {
17+
ul
18+
};
19+
}
20+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!--ssr:0--><ul><!--ssr:1--><!--ssr:7--><li>a</li><!--ssr:7--><!--ssr:1--></ul>
2+
<ul><!--ssr:2--><!--ssr:9--><li>a</li><!--ssr:9--><!--ssr:2--></ul>
3+
<ul><!--ssr:3--><!--ssr:11--><li>a</li><!--ssr:11--><!--ssr:3--></ul>
4+
<!--ssr:4--><!--ssr:13--><li>a</li>
5+
<li>a</li><!--ssr:13--><!--ssr:4-->
6+
<!--ssr:5--><!--ssr:15--><li>a</li>
7+
<li>a</li><!--ssr:15--><!--ssr:5-->
8+
<!--ssr:6--><!--ssr:17--><li>a</li>
9+
<li>a</li><!--ssr:17--><!--ssr:6--><!--ssr:0--></div>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<script>
2+
let { items } = $props();
3+
</script>
4+
5+
<ul>
6+
{#each items as item}
7+
<li>{item.name}</li>
8+
{/each}
9+
</ul>
10+
<ul>
11+
{#each items as item (item)}
12+
<li>{item.name}</li>
13+
{/each}
14+
</ul>
15+
<ul>
16+
{#each items as item (item.name)}
17+
<li>{item.name}</li>
18+
{/each}
19+
</ul>
20+
21+
{#each items as item}
22+
<li>{item.name}</li>
23+
<li>{item.name}</li>
24+
{/each}
25+
{#each items as item (item)}
26+
<li>{item.name}</li>
27+
<li>{item.name}</li>
28+
{/each}
29+
{#each items as item (item.name)}
30+
<li>{item.name}</li>
31+
<li>{item.name}</li>
32+
{/each}

0 commit comments

Comments
 (0)