Error Boundaries for Svelte
Svelte Error Boundary is a package that provides a simple error boundary component for Svelte. It can be used with both DOM and SSR targets. The package includes a default error boundary component that has an optional onError callback to log errors to services like Sentry. It also offers a createBoundary function that allows monkey-patching of existing Svelte components to create custom error state UIs. However, it should be noted that monkey-patching may break in future versions of Svelte, so this package is intended as a temporary solution for current production use of Svelte.
To install Svelte Error Boundary, you can follow these steps:
npm install svelte-error-boundary
or
yarn add svelte-error-boundary
import { ErrorBoundary } from 'svelte-error-boundary';
<ErrorBoundary>
<!-- Your Svelte component code here -->
</ErrorBoundary>
<ErrorBoundary onError={handleError}>
<!-- Your Svelte component code here -->
</ErrorBoundary>
import { createBoundary } from 'svelte-error-boundary';
import MyComponent from './MyComponent.svelte';
const ErrorBoundaryMyComponent = createBoundary(MyComponent);
Svelte Error Boundary is a package that provides a simple error boundary component for Svelte. It can be used with both DOM and SSR targets and offers an optional onError callback for logging errors. It also includes a createBoundary function for creating custom error state UIs. However, it should be noted that this package is intended as a temporary solution for current production use of Svelte, as monkey-patching may break in future versions of the framework.