-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add error boundaries #14211
feat: add error boundaries #14211
Conversation
🦋 Changeset detectedLatest commit: 4509d3b 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 |
preview: https://svelte-dev-git-preview-svelte-14211-svelte.vercel.app/ this is an automated message |
290dab2
to
be4c2cd
Compare
|
be4c2cd
to
ce5efe4
Compare
tweak tweak again retry -> reset tweaks add tests tweaks tweaks tweaks more tests more tests and tweaks comments tweak tweak tweak tweak tweak
ce5efe4
to
d2e035b
Compare
d2e035b
to
f683ce2
Compare
Can this be feature detected? Maybe there's a general way to feature detect |
Co-authored-by: Simon H <[email protected]>
Co-authored-by: Simon H <[email protected]>
Was kinda expecting the api to look like this {#boundary}
...
{:else e}
<div>An error occurred! {e}</div>
{/boundary} Maybe even {#try}
...
{:catch e}
<div>An error occurred! {e}</div>
{/try} Aren't error boundaries more like, control flow? |
What if you want to re-throw an error, or log an error to sentry? What if you want to render the error message somewhere else? We explored this API and it has too many drawbacks. Not to mention, |
What are you thinking about? Considering this should basically be for unexpected errors how would know about it help a library? |
lets say storybook used it, and a user using storybook is on svelte 5.1, if we add this with 5.2, storybook either has to release a breaking change to add a boundary to their stories or feature detect it so that @JReinhold you should be able to use the exported version from svelte/compiler and compare that its equal or larger to the first release of this feature. |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as off-topic.
This comment was marked as off-topic.
What if you don't want to show anything from inside the boundary if an error occurs, and instead use a fallback? Right now it seems that whatever has a chance to get rendered / added to the dom, stays in, which could result in a broken state. I added an |
Looks like a bug, looking into that now. Update:fixed! |
I like this, however, like other people, I am not sure about the execution of the idea; maybe it could be a logic block, as the |
They compose far better than logic blocks. For example, you can create custom error boundaries for your app using the same snippet pattern: <MyAppErrorBoundary>
<Content />
{#snippet failed(error)}
<ErrorMessage {error} />
{/snippet}
</MyAppErrorBoundary> |
@dominikg Unless I'm misunderstanding you, I'm not sure this is true, since it happens at the compiler level. So even if you only have the boundary on a condition based on the version, the compiler will still try to compile it and fail. This will still fail in v5.1:
See https://www.sveltelab.dev/5doeu6jrx5dqxj1?files=.%2Fsrc%2Froutes%2F%2Bpage.svelte |
I guess you could have a component that just renders the children snippet and one that wrap in boundary and dynamically import based on the condition |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple of small questions, inline, but LGTM
Co-authored-by: Rich Harris <[email protected]>
Co-authored-by: Rich Harris <[email protected]>
Co-authored-by: Rich Harris <[email protected]>
This PR adds support for error boundaries to Svelte. Specifically, it adds
<svelte:boundary>
, which is a special element that can capture errors that occur from within its subtree during client rendering (error boundaries are no-ops during SSR).The error boundary will capture all errors that occur in any effects (such as
$effect
and$effect.pre
) within its subtree, as long as the code is run synchronously (code in an async orsetTimeout
will not be captured).<svelte:boundary>
can report errors with usingonerror
, this can be a place where the error can be re-thrown to the next boundary:In addition, some fallback content can be rendered when an error occurs in a boundary using the
failed
snippet prop:Additionally, a
reset
function is passed as the second argument to bothonerror
and thefailed
prop:Feel free to play around with them on the playground.
Closes #3733, closes #14054