feat: allow error boundaries to catch errors on the server#15308
feat: allow error boundaries to catch errors on the server#15308dummdidumm wants to merge 11 commits intomainfrom
Conversation
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 detectedLatest commit: 2ad2d98 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
| remoteFunctions: false, | ||
| forkPreloads: false | ||
| forkPreloads: false, | ||
| serverErrorBoundaries: false |
There was a problem hiding this comment.
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 = ( |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
...maybe by making the data prop a getter that throws? 🤔
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Take advantage of sveltejs/svelte#17672 to add the
handleErrorhook astransformErrorso 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:
page.status, should it be passed as a prop to+error.svelte, too? What would it be in case of a rendering error though?handleErrorreceives 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 passnull?Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.