Skip to content

Comments

feat: allow error boundaries to catch errors on the server#15308

Draft
dummdidumm wants to merge 11 commits intomainfrom
error-boundaries-server
Draft

feat: allow error boundaries to catch errors on the server#15308
dummdidumm wants to merge 11 commits intomainfrom
error-boundaries-server

Conversation

@dummdidumm
Copy link
Member

@dummdidumm dummdidumm commented Feb 12, 2026

Take advantage of sveltejs/svelte#17672 to add the handleError hook as transformError so that error boundaries run on the server. Behind an experimental flag.

Closes #14808
Closes #14410
Closes #14398

New tests fail right now, install the other PR via pkg.new locally to see it in effect.

Todos:

  • what about page.status, should it be passed as a prop to +error.svelte, too? What would it be in case of a rendering error though?
  • what about the navigation event on the client? handleError receives one, but for render errors we don't have this context. Do a best effort of a stub, like "this was the URL this happened on" etc? Or just pass null?
  • a few others (see code)

Please don't delete this checklist! 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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

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

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Take advantage of sveltejs/svelte#17672 to add the `handleError` hook as `transformError` so that error boundaries run on the server. Behind an experimental flag.

Closes #14808
Closes #14410
Closes #14398
@changeset-bot
Copy link

changeset-bot bot commented Feb 12, 2026

🦋 Changeset detected

Latest commit: 2ad2d98

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Minor

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

@svelte-docs-bot
Copy link

remoteFunctions: false,
forkPreloads: false
forkPreloads: false,
serverErrorBoundaries: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a great alternative suggestion but I feel like serverErrorBoundaries doesn't totally cover it, since this also affects the behaviour of boundaries client-side


if (errors && __SVELTEKIT_EXPERIMENTAL_USE_TRANSFORM_ERROR__) {
let last_idx = -1;
result.props.errors = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in an ideal world, we wouldn't need to do all this — the error boundary self-activate. that would involve turning load errors into render errors. how achievable does that sound? (if the answer is 'lol not at all' then that's fine)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...maybe by making the data prop a getter that throws? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what you mean by this. This is about loading the +error.svelte components. We have to do this here upfront because we can't rely on using await in the template - it's still experimental and will be for a while.


/** @type {Array<import('types').SSRComponent | undefined> | undefined} */
let error_components;
if (options.server_error_boundaries && ssr) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants