Skip to content

Commit b9bc80d

Browse files
committed
add more test coverage
1 parent dc95bd3 commit b9bc80d

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function boundary(node, boundary_fn, props) {
5959
block(() => {
6060
var boundary = /** @type {Effect} */ (active_effect);
6161
var hydrate_open = hydrate_node;
62-
var is_rendering_failed = false;
62+
var is_creating_fallback = false;
6363

6464
// We re-use the effect's fn property to avoid allocation of an additional field
6565
boundary.fn = (/** @type { Error }} */ error) => {
@@ -75,9 +75,9 @@ export function boundary(node, boundary_fn, props) {
7575
}
7676

7777
// If we have nothing to capture the error then re-throw the error
78-
// for another boundary to handle, additionaly, if we're rendering
78+
// for another boundary to handle, additionaly, if we're creating
7979
// the fallback and that too fails, then re-throw the error
80-
if ((!onerror && !failed_snippet) || is_rendering_failed) {
80+
if ((!onerror && !failed_snippet) || is_creating_fallback) {
8181
throw error;
8282
}
8383

@@ -88,7 +88,7 @@ export function boundary(node, boundary_fn, props) {
8888
}
8989
with_boundary(boundary, () => {
9090
boundary_effect = null;
91-
is_rendering_failed = false;
91+
is_creating_fallback = false;
9292
boundary_effect = branch(() => boundary_fn(anchor));
9393
});
9494
};
@@ -104,7 +104,7 @@ export function boundary(node, boundary_fn, props) {
104104
queue_micro_task(() => {
105105
with_boundary(boundary, () => {
106106
boundary_effect = null;
107-
is_rendering_failed = true;
107+
is_creating_fallback = true;
108108
try {
109109
boundary_effect = branch(() => {
110110
failed_snippet(
@@ -116,7 +116,7 @@ export function boundary(node, boundary_fn, props) {
116116
} catch (error) {
117117
handle_error(/** @type {Error} */ (error), boundary, boundary.ctx);
118118
}
119-
is_rendering_failed = false;
119+
is_creating_fallback = false;
120120
});
121121
});
122122
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
let count = $state(0);
3+
4+
$effect.pre(() => {
5+
if (count > 1) {
6+
throw new Error('too high');
7+
}
8+
});
9+
</script>
10+
11+
{count}
12+
13+
<button onclick={() => count++}>+</button>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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']);
13+
assert.htmlEqual(target.innerHTML, `<div>An error occurred!</div>\n0\n<button>+</button>`);
14+
15+
btn = target.querySelector('button');
16+
17+
btn?.click();
18+
btn?.click();
19+
flushSync();
20+
21+
assert.deepEqual(logs, ['error caught', 'error caught']);
22+
assert.htmlEqual(target.innerHTML, `<div>An error occurred!</div>\n0\n<button>+</button>`);
23+
}
24+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
import Child from './Child.svelte';
3+
</script>
4+
5+
<svelte:boundary onerror={(e) => console.log('error caught')}>
6+
<Child />
7+
8+
{#snippet failed(err, reset)}
9+
<div>An error occurred!</div>
10+
<Child />
11+
{/snippet}
12+
</svelte:boundary>

0 commit comments

Comments
 (0)