Skip to content

Commit 4d8ad24

Browse files
committed
more bug fixes
1 parent cf11f58 commit 4d8ad24

File tree

7 files changed

+77
-11
lines changed

7 files changed

+77
-11
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,6 @@ export function boundary(node, boundary_fn, props) {
6666
var onerror = props.onerror;
6767
let failed_snippet = props.failed;
6868

69-
if (boundary_effect) {
70-
destroy_effect(boundary_effect);
71-
} else if (hydrating) {
72-
set_hydrate_node(hydrate_open);
73-
next();
74-
set_hydrate_node(remove_nodes());
75-
}
76-
7769
// If we have nothing to capture the error then re-throw the error
7870
// for another boundary to handle, additionaly, if we're creating
7971
// the fallback and that too fails, then re-throw the error
@@ -98,6 +90,14 @@ export function boundary(node, boundary_fn, props) {
9890
onerror(error, reset);
9991
}
10092

93+
if (boundary_effect) {
94+
destroy_effect(boundary_effect);
95+
} else if (hydrating) {
96+
set_hydrate_node(hydrate_open);
97+
next();
98+
set_hydrate_node(remove_nodes());
99+
}
100+
101101
// Handle the `failed` snippet fallback
102102
if (failed_snippet) {
103103
// Ensure we create the boundary branch after the catch event cycle finishes

packages/svelte/src/internal/client/reactivity/effects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,12 @@ export function destroy_effect(effect, remove_dom = true) {
464464
}
465465

466466
// `first` and `child` are nulled out in destroy_effect_children
467+
// we don't null out `parent` so that error propagation can work correctly
467468
effect.next =
468469
effect.prev =
469470
effect.teardown =
470471
effect.ctx =
471472
effect.deps =
472-
effect.parent =
473473
effect.fn =
474474
effect.nodes_start =
475475
effect.nodes_end =

packages/svelte/src/internal/client/runtime.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ function process_effects(effect, collected_effects) {
669669
var flags = current_effect.f;
670670
var is_branch = (flags & BRANCH_EFFECT) !== 0;
671671
var is_skippable_branch = is_branch && (flags & CLEAN) !== 0;
672+
var sibling = current_effect.next;
672673

673674
if (!is_skippable_branch && (flags & INERT) === 0) {
674675
if ((flags & RENDER_EFFECT) !== 0) {
@@ -695,8 +696,6 @@ function process_effects(effect, collected_effects) {
695696
}
696697
}
697698

698-
var sibling = current_effect.next;
699-
700699
if (sibling === null) {
701700
let parent = current_effect.parent;
702701

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
test({ assert, target }) {
6+
let btn = target.querySelector('button');
7+
8+
btn?.click();
9+
btn?.click();
10+
11+
assert.throws(() => {
12+
flushSync();
13+
}, /test\n\n\tin {expression}\n/);
14+
}
15+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script>
2+
let count = $state(0);
3+
4+
let test = $derived.by(() => {
5+
if (count > 1) {
6+
throw new Error('test');
7+
}
8+
});
9+
</script>
10+
11+
<svelte:boundary onerror={(e) => { throw(e) }}>
12+
<div>Count: {count}</div>
13+
<button onclick={() => count++}>Increment</button>
14+
{count} / {test}
15+
</svelte:boundary>
16+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
test({ assert, target, logs }) {
6+
let btn = target.querySelector('button');
7+
8+
btn?.click();
9+
btn?.click();
10+
flushSync();
11+
12+
assert.deepEqual(logs, ['error caught 1', 'error caught 2']);
13+
}
14+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<script>
2+
let count = $state(0);
3+
4+
let test = $derived.by(() => {
5+
if (count > 1) {
6+
throw new Error('test');
7+
}
8+
});
9+
</script>
10+
11+
<svelte:boundary onerror={(e) => {console.log('error caught 1')}}>
12+
<div>Count: {count}</div>
13+
<button onclick={() => count++}>Increment</button>
14+
{count} / {test}
15+
</svelte:boundary>
16+
17+
18+
<svelte:boundary onerror={(e) => {console.log('error caught 2')}}>
19+
<div>Count: {count}</div>
20+
<button onclick={() => count++}>Increment</button>
21+
{count} / {test}
22+
</svelte:boundary>

0 commit comments

Comments
 (0)