Skip to content

Commit 0c1ba87

Browse files
committed
more fixes
1 parent e0bdf2c commit 0c1ba87

File tree

4 files changed

+63
-15
lines changed

4 files changed

+63
-15
lines changed

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -567,22 +567,28 @@ function flush_queued_effects(effects) {
567567
for (var i = 0; i < length; i++) {
568568
var effect = effects[i];
569569

570-
if ((effect.f & (DESTROYED | INERT)) === 0 && check_dirtiness(effect)) {
571-
update_effect(effect);
572-
573-
// Effects with no dependencies or teardown do not get added to the effect tree.
574-
// Deferred effects (e.g. `$effect(...)`) _are_ added to the tree because we
575-
// don't know if we need to keep them until they are executed. Doing the check
576-
// here (rather than in `update_effect`) allows us to skip the work for
577-
// immediate effects.
578-
if (effect.deps === null && effect.first === null && effect.nodes_start === null) {
579-
if (effect.teardown === null) {
580-
// remove this effect from the graph
581-
unlink_effect(effect);
582-
} else {
583-
// keep the effect in the graph, but free up some memory
584-
effect.fn = null;
570+
if ((effect.f & (DESTROYED | INERT)) === 0) {
571+
try {
572+
if (check_dirtiness(effect)) {
573+
update_effect(effect);
574+
575+
// Effects with no dependencies or teardown do not get added to the effect tree.
576+
// Deferred effects (e.g. `$effect(...)`) _are_ added to the tree because we
577+
// don't know if we need to keep them until they are executed. Doing the check
578+
// here (rather than in `update_effect`) allows us to skip the work for
579+
// immediate effects.
580+
if (effect.deps === null && effect.first === null && effect.nodes_start === null) {
581+
if (effect.teardown === null) {
582+
// remove this effect from the graph
583+
unlink_effect(effect);
584+
} else {
585+
// keep the effect in the graph, but free up some memory
586+
effect.fn = null;
587+
}
588+
}
585589
}
590+
} catch (error) {
591+
handle_error(/** @type {Error} */ (error), effect, effect.ctx);
586592
}
587593
}
588594
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
const { things } = $props();
3+
4+
$effect(() => {
5+
things
6+
})
7+
</script>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
test({ assert, target, logs }) {
6+
const btn = target.querySelector('button');
7+
8+
btn?.click();
9+
flushSync();
10+
11+
assert.htmlEqual(target.innerHTML, `<button>change</button><p>Error occured</p>`);
12+
}
13+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<script>
2+
import Child from './Child.svelte';
3+
4+
let count = $state(0);
5+
6+
const things = $derived.by(() => {
7+
if (count === 1) {
8+
throw new Error('123')
9+
}
10+
return [1, 2 ,3]
11+
})
12+
</script>
13+
14+
<button onclick={() => count++}>change</button>
15+
16+
<svelte:boundary>
17+
<Child {things} />
18+
19+
{#snippet failed()}
20+
<p>Error occured</p>
21+
{/snippet}
22+
</svelte:boundary>

0 commit comments

Comments
 (0)