Skip to content

Conversation

Rich-Harris
Copy link
Member

Decided to take a look at our error handling logic. It's rather convoluted and also wrong.

If you have a situation like this...

<!-- App.svelte -->
<script>
  import Component from './Component.svelte';
</script>

<svelte:boundary>
  <Component />
	
  {#snippet failed()}
    <p>outer failed</p>
  {/snippet}
</svelte:boundary>
<script>
  let d = $derived.by(() => {
    throw new Error('kaboom');
  });
</script>

<svelte:boundary>
  {d}
	
  {#snippet failed()}
    <p>inner failed</p>
  {/snippet}
</svelte:boundary>

...the inner boundary fails, even though d is declared outside it. That's obviously incorrect (you can't have boundaries triggering non-deterministically based on where a value happens to be read first). Bit embarrassed I didn't catch this in the initial review.

This PR fixes that behaviour and also simplifies things a decent amount (no more is_throwing_error and should_rethrow_error and previous_effect and other hard-to-follow stuff) and removes some hot path try-catches. It also continues the project of slimming down runtime.js in favour of different modules for different purposes — we're finally under 1,000 LOC.

Before submitting the PR, please make sure you do the following

  • 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
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Jun 6, 2025

🦋 Changeset detected

Latest commit: da2c8a9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Jun 6, 2025

Playground

pnpm add https://pkg.pr.new/svelte@16091

@Rich-Harris Rich-Harris merged commit 2d2772a into main Jun 6, 2025
14 checks passed
@Rich-Harris Rich-Harris deleted the simplify-handle-error branch June 6, 2025 17:53
@github-actions github-actions bot mentioned this pull request Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants