@flareapp/svelte 2.0.0-alpha.0 → 2.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,105 +1,33 @@
1
1
  # @flareapp/svelte
2
2
 
3
- Svelte 5 integration for [Flare](https://flareapp.io) error tracking. It provides a native Svelte error boundary and a
4
- handler factory for custom `<svelte:boundary>` usage. It builds on top of `@flareapp/js`, which still handles the core
5
- Flare client configuration, global browser errors, manual reports, custom context, and glows.
3
+ Svelte 5 integration for [Flare](https://flareapp.io) error tracking. Provides an error boundary component that catches
4
+ component errors and reports them to Flare with Svelte-specific context (component name, hierarchy, error origin).
6
5
 
7
6
  ## Installation
8
7
 
9
- Install both the core Flare client and the Svelte integration:
10
-
11
8
  ```bash
12
- npm install @flareapp/js @flareapp/svelte
13
- # or
14
- yarn add @flareapp/js @flareapp/svelte
15
- # or
16
- pnpm add @flareapp/js @flareapp/svelte
9
+ npm install @flareapp/svelte @flareapp/js
17
10
  ```
18
11
 
19
- `@flareapp/svelte` supports Svelte 5.3 and higher.
20
-
21
- If your app is bundled for production, also configure sourcemap uploads with `@flareapp/vite` so Flare can show readable
22
- stack traces and code snippets.
23
-
24
- ## Setting up the Flare client
25
-
26
- Initialize the Flare client as early as possible in your application, typically in `main.ts`:
12
+ ## Quick start
27
13
 
28
- ```ts
29
- import { flare } from '@flareapp/js';
30
- import { mount } from 'svelte';
31
-
32
- import App from './App.svelte';
33
-
34
- if (import.meta.env.PROD) {
35
- flare.light('YOUR PROJECT PUBLIC KEY');
36
- }
37
-
38
- mount(App, {
39
- target: document.getElementById('app')!,
40
- });
41
- ```
42
-
43
- Use your project's public key from the JavaScript installation section in your Flare project settings.
44
-
45
- If you use the sourcemap plugin, you do not need to pass a public key to `flare.light()`. The plugin injects the project
46
- key during your build.
47
-
48
- ## Error boundary
49
-
50
- `FlareErrorBoundary` wraps Svelte's native `<svelte:boundary>`. It catches errors from the component tree below it,
51
- reports them to Flare, and can render your fallback snippet.
14
+ Initialize the Flare client and wrap your component tree with the error boundary:
52
15
 
53
16
  ```svelte
54
17
  <script lang="ts">
18
+ import { flare } from '@flareapp/js';
55
19
  import { FlareErrorBoundary } from '@flareapp/svelte';
56
20
 
57
21
  import Root from './Root.svelte';
22
+
23
+ if (import.meta.env.PROD) {
24
+ flare.light('YOUR_FLARE_API_KEY');
25
+ }
58
26
  </script>
59
27
 
60
28
  <FlareErrorBoundary>
61
29
  <Root />
62
30
 
63
- {#snippet failed(error, reset)}
64
- <section>
65
- <h2>Something went wrong</h2>
66
- <p>{error.message}</p>
67
- <button onclick={reset}>Try again</button>
68
- </section>
69
- {/snippet}
70
- </FlareErrorBoundary>
71
- ```
72
-
73
- Without a `failed` snippet, the boundary still catches and reports the error, but it renders nothing for the failed
74
- subtree.
75
-
76
- ### Resetting the boundary
77
-
78
- Call the `reset` function passed to the `failed` snippet to clear the boundary state and retry rendering the children:
79
-
80
- ```svelte
81
- <FlareErrorBoundary>
82
- <CheckoutForm />
83
-
84
- {#snippet failed(error, reset)}
85
- <p>{error.message}</p>
86
- <button onclick={reset}>Retry checkout</button>
87
- {/snippet}
88
- </FlareErrorBoundary>
89
- ```
90
-
91
- You can also reset automatically when values in `resetKeys` change. Values are compared by index with `Object.is`, and a
92
- length change also triggers a reset.
93
-
94
- ```svelte
95
- <FlareErrorBoundary
96
- resetKeys={[currentRoute, selectedAccountId]}
97
- onReset={(error) => {
98
- console.log('Recovered from:', error?.message);
99
- }}
100
- >
101
- <AccountPage />
102
-
103
31
  {#snippet failed(error, reset)}
104
32
  <p>{error.message}</p>
105
33
  <button onclick={reset}>Try again</button>
@@ -107,258 +35,19 @@ length change also triggers a reset.
107
35
  </FlareErrorBoundary>
108
36
  ```
109
37
 
110
- `onReset` runs when the user calls `reset` from the fallback snippet or when `resetKeys` changes while the boundary is in
111
- an error state. It receives the previous error, or `null` if no error was stored.
112
-
113
- ## Lifecycle callbacks
114
-
115
- The boundary exposes three callbacks around the Svelte-specific reporting flow.
116
-
117
- ```svelte
118
- <script lang="ts">
119
- import { flare } from '@flareapp/js';
120
- import { FlareErrorBoundary, type FlareSvelteContext } from '@flareapp/svelte';
121
- </script>
122
-
123
- <FlareErrorBoundary
124
- beforeEvaluate={({ error }) => {
125
- flare.addContext('feature', 'checkout');
126
- flare.addContext('errorMessage', error.message);
127
- }}
128
- beforeSubmit={({ context }: { context: FlareSvelteContext }) => {
129
- return {
130
- ...context,
131
- svelte: {
132
- ...context.svelte,
133
- componentHierarchy: context.svelte.componentHierarchy.filter(
134
- (component) => component !== 'ThirdPartyWrapper',
135
- ),
136
- },
137
- };
138
- }}
139
- afterSubmit={({ error, context }) => {
140
- console.error('Reported Svelte error:', error);
141
- console.debug('Svelte context:', context);
142
- }}
143
- >
144
- <Root />
145
- </FlareErrorBoundary>
146
- ```
147
-
148
- Callback order:
149
-
150
- 1. `beforeEvaluate` runs after the thrown value is converted to an `Error`, before Svelte context is built.
151
- 2. `beforeSubmit` runs after Svelte context is built. Return the context object that should be attached to the report.
152
- 3. `afterSubmit` runs after Flare reporting is started. The network request is asynchronous.
153
-
154
- These callbacks are not wrapped in `try`/`catch`. If one throws, the error can bubble out of the boundary handler.
155
-
156
- ### Filtering errors
157
-
158
- The boundary callbacks are for adding context and running side effects. They do not suppress reports.
159
-
160
- To filter, suppress, or modify the final Flare report, use the core JavaScript client hooks:
161
-
162
- ```ts
163
- import { flare } from '@flareapp/js';
164
-
165
- flare.configure({
166
- beforeEvaluate: (error) => {
167
- if (error.message.includes('Ignored validation error')) {
168
- return false;
169
- }
170
-
171
- return error;
172
- },
173
- });
174
- ```
175
-
176
- The execution order when both boundary callbacks and core client hooks are configured is:
177
-
178
- 1. Boundary `beforeEvaluate`
179
- 2. Boundary `beforeSubmit`
180
- 3. Internal `flare.reportSilently()` call
181
- 4. Client `beforeEvaluate` from `flare.configure()`
182
- 5. Client `beforeSubmit` from `flare.configure()`
183
- 6. Report is sent to Flare
184
- 7. Boundary `afterSubmit`
185
-
186
- ## Svelte context
187
-
188
- When the Svelte integration reports an error, it attaches Svelte-specific context under `context.custom.svelte`.
189
-
190
- ```ts
191
- interface FlareSvelteContext {
192
- svelte: {
193
- componentName: string | null;
194
- componentHierarchy: string[];
195
- errorOrigin: 'render' | 'event' | 'effect' | 'unknown';
196
- };
197
- }
198
- ```
199
-
200
- Field details:
201
-
202
- | Field | Description |
203
- | -------------------- | ---------------------------------------------------------------- |
204
- | `componentName` | Best-effort name of the component closest to the thrown error. |
205
- | `componentHierarchy` | Component names ordered from inner component to outer component. |
206
- | `errorOrigin` | Best-effort classification of where the error came from. |
207
-
208
- When the same component is mounted in multiple places (e.g. a `Button` inside both `Sidebar` and `Header`),
209
- `FlareErrorBoundary` disambiguates by matching the error to the instance whose ancestor chain includes the catching
210
- boundary. Without an ancestor hint (e.g. manual `lookupComponentTree` calls), the first registered instance is returned.
211
-
212
- Component context is extracted from `.svelte` stack frames. In production bundles, function names and filenames may be
213
- minified. Configure sourcemaps so Flare can resolve the original source code on the backend.
214
-
215
- ## Event handlers and async errors
216
-
217
- Svelte boundaries do not catch every kind of browser error. Errors thrown in event handlers and unhandled promise
218
- rejections are handled by the global listeners installed by `@flareapp/js`, not by `FlareErrorBoundary`.
219
-
220
- ```svelte
221
- <button
222
- onclick={() => {
223
- throw new Error('Clicked button failed');
224
- }}
225
- >
226
- Trigger event error
227
- </button>
228
- ```
229
-
230
- The error above is still reported if the core Flare client is initialized, but it will not render the boundary fallback
231
- UI.
232
-
233
- ## Custom boundary usage
234
-
235
- Use `createFlareErrorHandler()` when you want to wire Flare into your own `<svelte:boundary>` instead of using
236
- `FlareErrorBoundary`.
237
-
238
- ```svelte
239
- <script lang="ts">
240
- import { createFlareErrorHandler } from '@flareapp/svelte';
241
-
242
- const reportToFlare = createFlareErrorHandler({
243
- afterSubmit: ({ error }) => {
244
- console.error('Reported through custom boundary:', error);
245
- },
246
- });
247
- </script>
248
-
249
- <svelte:boundary onerror={reportToFlare}>
250
- <Root />
251
-
252
- {#snippet failed(error, reset)}
253
- <p>{error.message}</p>
254
- <button onclick={reset}>Retry</button>
255
- {/snippet}
256
- </svelte:boundary>
257
- ```
258
-
259
- The returned function matches the Svelte boundary `onerror` signature:
260
-
261
- ```ts
262
- (error: unknown, reset: () => void) => void | Promise<void>;
263
- ```
264
-
265
- It converts non-`Error` values, builds Svelte context from the stack trace, reports through the core Flare client, and
266
- runs the lifecycle callbacks described above.
38
+ ## Documentation
267
39
 
268
- ## Manual reports, context, and glows
40
+ Full documentation on the error boundary, lifecycle callbacks, reset keys, custom boundary usage, and more is available
41
+ at [flareapp.io/docs/svelte/general/installation](https://flareapp.io/docs/svelte/general/installation).
269
42
 
270
- The Svelte integration builds on the core JavaScript client. Use `@flareapp/js` directly for manual reporting, client
271
- hooks, custom context, and glows:
272
-
273
- ```ts
274
- import { flare } from '@flareapp/js';
275
-
276
- flare.addContext('user', { id: '123' });
277
- flare.glow('checkout', 'Payment method selected');
278
-
279
- try {
280
- await submitOrder();
281
- } catch (error) {
282
- flare.report(error);
283
- }
284
- ```
285
-
286
- Useful shared documentation:
287
-
288
- - [Reporting errors](https://flareapp.io/docs/javascript/errors/reporting-errors)
289
- - [Client hooks](https://flareapp.io/docs/javascript/errors/client-hooks)
290
- - [Adding custom context](https://flareapp.io/docs/javascript/data-collection/adding-custom-context)
291
- - [Adding glows](https://flareapp.io/docs/javascript/data-collection/adding-glows)
292
-
293
- ## Resolving bundled code
294
-
295
- Production Svelte apps are usually minified and bundled, which makes raw stack traces hard to read. Configure sourcemap
296
- uploads with `@flareapp/vite` so Flare can map stack frames back to your original `.svelte` files.
297
-
298
- The Svelte integration uses the same sourcemap plugin as the JavaScript and React clients. See the
299
- [JavaScript resolving bundled code documentation](https://flareapp.io/docs/javascript/general/resolving-bundled-code)
300
- for the Vite, Webpack, Laravel Mix, and manual upload setup.
301
-
302
- ## Verifying your setup
303
-
304
- The core client is available as `window.flare` in the browser. Build your app for production and run this in the browser
305
- console:
306
-
307
- ```js
308
- flare.test();
309
- ```
310
-
311
- This sends a test error to your Flare project.
312
-
313
- If nothing appears in Flare, enable debug mode:
314
-
315
- ```ts
316
- flare.light('YOUR PROJECT PUBLIC KEY', true);
317
- // or
318
- flare.configure({ debug: true });
319
- ```
320
-
321
- If `flare.light()` has not been called, for example because your production guard is false, reports are silently ignored.
322
-
323
- ## API reference
324
-
325
- ```ts
326
- import { FlareErrorBoundary, createFlareErrorHandler } from '@flareapp/svelte';
327
-
328
- import type { FlareErrorHandlerOptions, FlareSvelteContext, SvelteErrorOrigin } from '@flareapp/svelte';
329
- ```
330
-
331
- Exports:
332
-
333
- | Export | Description |
334
- | ------------------------- | --------------------------------------------------------------------------------------------------------------- |
335
- | `FlareErrorBoundary` | Svelte component that catches boundary errors, reports them to Flare, and renders an optional fallback snippet. |
336
- | `createFlareErrorHandler` | Factory that returns a Svelte boundary `onerror` callback for custom boundary usage. |
337
-
338
- Types:
339
-
340
- | Type | Description |
341
- | -------------------------- | ------------------------------------------------------------------------------------------ |
342
- | `FlareErrorHandlerOptions` | Lifecycle callback options accepted by `createFlareErrorHandler` and `FlareErrorBoundary`. |
343
- | `FlareSvelteContext` | Shape of the Svelte context passed to `beforeSubmit` and `afterSubmit`. |
344
- | `SvelteErrorOrigin` | Union of possible origin values: `'render'`, `'event'`, `'effect'`, and `'unknown'`. |
345
-
346
- ### `FlareErrorBoundary` props
43
+ ## SvelteKit
347
44
 
348
- | Prop | Type | Description |
349
- | ---------------- | -------------------------------------------- | --------------------------------------------------------------------- |
350
- | `children` | `Snippet` | Child snippet rendered inside the boundary. |
351
- | `failed` | `Snippet<[error: Error, reset: () => void]>` | Optional fallback snippet rendered after an error is caught. |
352
- | `resetKeys` | `unknown[]` | Values that reset the boundary when changed while an error is stored. |
353
- | `beforeEvaluate` | `({ error }) => void` | Runs before Svelte context is built. |
354
- | `beforeSubmit` | `({ error, context }) => FlareSvelteContext` | Runs before reporting. Return the context to attach. |
355
- | `afterSubmit` | `({ error, context }) => void` | Runs after reporting is started. |
356
- | `onReset` | `(error: Error &#124; null) => void` | Runs when the boundary is reset. |
45
+ For SvelteKit apps, install `@flareapp/sveltekit` as well. It adds client and server `handleError` helpers, route
46
+ context tracking, and re-exports the Svelte boundary component.
357
47
 
358
- ## SvelteKit
48
+ ## Compatibility
359
49
 
360
- For SvelteKit apps, install `@flareapp/sveltekit` as well. It adds client and server `handleError` helpers, manual
361
- SvelteKit capture helpers, route context, and re-exports the Svelte boundary component for convenience.
50
+ - Svelte 5.3+
362
51
 
363
52
  ## License
364
53
 
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "2.0.0-alpha.0";
1
+ export declare const PACKAGE_VERSION = "2.0.0-alpha.1";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated during release, do not modify
2
- export const PACKAGE_VERSION = '2.0.0-alpha.0';
2
+ export const PACKAGE_VERSION = '2.0.0-alpha.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flareapp/svelte",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.0-alpha.1",
4
4
  "description": "Svelte client for flareapp.io",
5
5
  "homepage": "https://flareapp.io",
6
6
  "bugs": "https://github.com/spatie/flare-client-js/issues",