mirror of https://github.com/sveltejs/svelte
fix: propagate `$effect` errors to `<svelte:boundary>` (#17684)
Fixes #16342. Errors thrown inside `$effect` were previously treated as subtree-creation errors when `EFFECT_RAN === 0`, which caused them to be rethrown instead of propagating to the nearest `<svelte:boundary>`. As a result, `$effect` errors bypassed boundaries and appeared as uncaught runtime errors. This change ensures that errors originating from effects (`EFFECT`) are routed through `invoke_error_boundary`, allowing them to bubble up the effect tree and be handled correctly by the closest boundary. Existing subtree-creation behavior for non-effect cases remains unchanged. --- ### Before submitting the PR, please make sure you do the following - [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs - [x] Prefix your PR title with `feat:`, `fix:`, `chore:`, or `docs:`. - [x] This message body should clearly illustrate what problems it solves. - [x] Ideally, include a test that fails without this PR but passes with it. - [x] If this PR changes code within `packages/svelte/src`, add a changeset (`npx changeset`). ### Tests and linting - [x] Run the tests with `pnpm test` and lint the project with `pnpm lint` --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/17681/head
parent
b657029687
commit
45a796b327
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: propagate `$effect` errors to `<svelte:boundary>`
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
<script>
|
||||||
|
$effect(() => {
|
||||||
|
throw new Error('boom');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
// allow effects to run / microtasks to flush
|
||||||
|
await Promise.resolve();
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, '<p>caught: boom</p>');
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
<script>
|
||||||
|
import Test from './Test.svelte';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:boundary>
|
||||||
|
<Test />
|
||||||
|
|
||||||
|
{#snippet failed(e)}
|
||||||
|
<p>caught: {e.message}</p>
|
||||||
|
{/snippet}
|
||||||
|
</svelte:boundary>
|
||||||
Loading…
Reference in new issue