npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-error-boundary

v1.0.2

Published

Fix error boundary Svelte 3 problem to prevent full app crash

Downloads

210

Readme

svelte-error-boundary

NPM version NPM downloads Svelte v3

Partly fix error boundary Svelte 3 problem to prevent full app crash on initialization

:warning: Warning: this package fixes only the problem with initialization errors. Runtime errors could not be handled with this approach

The key issue is that some of the built-in methods need to be wrapped in Svelte to create runtime error handling support, but there is only one pure "true" way to do this, and that is by implementing this built-in feature in Svelte.

There is another "runtime" error boundary package called @crownframework/svelte-error-boundary. But it also does not handle all errors due to this array of Svelte methods GUARDED_BLOCK_FNS, view this issue: "That you for reporting this. This does indeed seem to be either a bug or – more likely – a limitation of the current implementation". Another potential disadvantave of @crownframework/svelte-error-boundary is too much more created try...catch blocks. This could affect the browser's built-in code optimizations. For example, according to this Stack Overflow answer: "The problem is that V8 didn't support it in their optimizing compiler until version 6 of the engine, so the entire containing function that syntactically contains a try catch will not be optimized". And according Wikipedia V8 6.0 is equal to Chrome 60. The presence of a large number of try...catch blocks will slow down browsers younger than Chrome 60.

:cake: Features

Right now Svelte 3 has no built-in error handling in components out of the box. To solve this issue this package was created inspired by this thread.

  • Simply applies Javascript try...catch statement to child components :lock:
  • Easy to use (as traditional component)

Install

npm i svelte-error-boundary

Usage

<script>
  import ErrorBoundary from 'svelte-error-boundary'

  ...
</script>

<ErrorBoundary name="custom try catch">
  <BrokenComponent />
</ErrorBoundary>

API

Parameters

| Name | Type | Default | Description | | ----------- | -------- | ----------- | --------------------------- | | name | string | undefined | Custom name for error scope | | handleError | function | undefined | Function to handle error |

Function handleError(error, name) can be used to send error logs to server and so on.

Note that this component does not support SSR (svelte.compile with option: generate: 'ssr') and does not support hydration (svelte.compile with option: hydratable: true).

Please use this ErrorBoundary component directly over the BrokenComponent, otherwise errors may appear outside. You can manually test the ErrorBoundary component by inserting throw new Error('test') inside your component.

License

MIT © Denis Stasyev