Skip to content

Commit bac569d

Browse files
authored
Merge branch 'main' into main
2 parents 754d92f + 9d97da3 commit bac569d

File tree

20 files changed

+458
-40
lines changed

20 files changed

+458
-40
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
title: Advent of Svelte
3+
description: Twenty-four days, twenty-four features
4+
author: The Svelte team
5+
authorURL: https://svelte.dev/
6+
pinnedUntil: 2024-12-26
7+
---
8+
9+
Last December, [Svelte Society](https://bsky.app/profile/sveltesociety.dev) presented an advent calendar's worth of [festive Svelte-themed code challenges](https://advent.sveltesociety.dev/).
10+
11+
This year, we're turning it around: you get to relax while _we_ take on a challenge. We've set ourselves a goal of releasing one thing a day from here until Christmas, whether it's a new feature in Svelte or SvelteKit or an improvement to the website.
12+
13+
Follow [@svelte.dev](https://bsky.app/profile/svelte.dev) and [@sveltesociety.dev](https://bsky.app/profile/sveltesociety.dev) and check back every day to see what we've been cooking up.
14+
15+
## Day 1: Error boundaries
16+
17+
This is a long-awaited and much-requested feature, that allows you to isolate and recover from errors that occur during rendering.
18+
19+
- [docs](/docs/svelte/svelte-boundary)
20+
- [tutorial](/tutorial/svelte/svelte-boundary)
21+
22+
## Day 2: `each` without `as`
23+
24+
If you just want to render something in an `{#each ...}` block _n_ times, and don't care about the value, you can now omit the `as` part.
25+
26+
- [docs](/docs/svelte/each#Each-blocks-without-an-item)
27+
- [demo](/playground/untitled#H4sIAAAAAAAAE3WR0W7CMAxFf8XKNAk0WsSeUEaRpn3Guoc0MbQiJFHiMlDVf18SOrZJ48259_jaVgZmxBEZZ28thgCNFV6xBdt1GgPj7wOji0t2EqI-wa_OleGEmpLWiID_6dIaQkMxhm1UdwKpRQhVzWSaVORJNdvWpqbhAYVsYQCNZk8thzWMC_DCHMZk3wPSThNQ088I3mghD9UwSwHwlLE5PMIzVFUFq3G7WUZ2OyUvU3JOuZU332wCXTRmtPy1NgzXZtUFp8WFw9536uWqpbIgPEaDsJBW90cTOHh0KGi2XsBq5-cT6-3nPauxXqHnsHJnCFZ3CvJVkyuCQ0mFF9TZyCQ162WGvteLKfG197Y3iv_pz_fmS68Hxt8iPBPj5HscP8YvCNX7uhYCAAA=)
28+
29+
## Day 3
30+
31+
Coming soon!
32+
33+
## Day 4
34+
35+
Coming soon!
36+
37+
## Day 5
38+
39+
Coming soon!
40+
41+
## Day 6
42+
43+
Coming soon!
44+
45+
## Day 7
46+
47+
Coming soon!
48+
49+
## Day 8
50+
51+
Coming soon!
52+
53+
## Day 9
54+
55+
Coming soon!
56+
57+
## Day 10
58+
59+
Coming soon!
60+
61+
## Day 11
62+
63+
Coming soon!
64+
65+
## Day 12
66+
67+
Coming soon!
68+
69+
## Day 13
70+
71+
Coming soon!
72+
73+
## Day 14
74+
75+
Coming soon!
76+
77+
## Day 15
78+
79+
Coming soon!
80+
81+
## Day 16
82+
83+
Coming soon!
84+
85+
## Day 17
86+
87+
Coming soon!
88+
89+
## Day 18
90+
91+
Coming soon!
92+
93+
## Day 19
94+
95+
Coming soon!
96+
97+
## Day 20
98+
99+
Coming soon!
100+
101+
## Day 21
102+
103+
Coming soon!
104+
105+
## Day 22
106+
107+
Coming soon!
108+
109+
## Day 23
110+
111+
Coming soon!
112+
113+
## Day 24
114+
115+
Coming soon!

apps/svelte.dev/content/docs/kit/25-build-and-deploy/60-adapter-cloudflare.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ To include type declarations for your bindings, reference them in your `src/app.
8686

8787
```ts
8888
/// file: src/app.d.ts
89+
import { KVNamespace, DurableObjectNamespace } from '@cloudflare/workers-types';
90+
8991
declare global {
9092
namespace App {
9193
interface Platform {

apps/svelte.dev/content/docs/kit/25-build-and-deploy/70-adapter-cloudflare-workers.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ To include type declarations for your bindings, reference them in your `src/app.
107107

108108
```ts
109109
/// file: src/app.d.ts
110+
import { KVNamespace, DurableObjectNamespace } from '@cloudflare/workers-types';
111+
110112
declare global {
111113
namespace App {
112114
interface Platform {

apps/svelte.dev/content/docs/svelte/03-template-syntax/03-each.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,30 @@ You can freely use destructuring and rest patterns in each blocks.
7474
{/each}
7575
```
7676

77+
## Each blocks without an item
78+
79+
```svelte
80+
<!--- copy: false --->
81+
{#each expression}...{/each}
82+
```
83+
84+
```svelte
85+
<!--- copy: false --->
86+
{#each expression, index}...{/each}
87+
```
88+
89+
In case you just want to render something `n` times, you can omit the `as` part ([demo](/playground/untitled#H4sIAAAAAAAAE3WR0W7CMAxFf8XKNAk0WsSeUEaRpn3Guoc0MbQiJFHiMlDVf18SOrZJ48259_jaVgZmxBEZZ28thgCNFV6xBdt1GgPj7wOji0t2EqI-wa_OleGEmpLWiID_6dIaQkMxhm1UdwKpRQhVzWSaVORJNdvWpqbhAYVsYQCNZk8thzWMC_DCHMZk3wPSThNQ088I3mghD9UwSwHwlLE5PMIzVFUFq3G7WUZ2OyUvU3JOuZU332wCXTRmtPy1NgzXZtUFp8WFw9536uWqpbIgPEaDsJBW90cTOHh0KGi2XsBq5-cT6-3nPauxXqHnsHJnCFZ3CvJVkyuCQ0mFF9TZyCQ162WGvteLKfG197Y3iv_pz_fmS68Hxt8iPBPj5HscP8YvCNX7uhYCAAA=)):
90+
91+
```svelte
92+
<div class="chess-board">
93+
{#each { length: 8 }, rank}
94+
{#each { length: 8 }, file}
95+
<div class:black={(rank + file) % 2 === 1}></div>
96+
{/each}
97+
{/each}
98+
</div>
99+
```
100+
77101
## Else blocks
78102

79103
```svelte
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: <svelte:boundary>
3+
---
4+
5+
```svelte
6+
<svelte:boundary onerror={handler}>...</svelte:boundary>
7+
```
8+
9+
> [!NOTE]
10+
> This feature was added in 5.3.0
11+
12+
Boundaries allow you to guard against errors in part of your app from breaking the app as a whole, and to recover from those errors.
13+
14+
If an error occurs while rendering or updating the children of a `<svelte:boundary>`, or running any [`$effect`]($effect) functions contained therein, the contents will be removed.
15+
16+
Errors occurring outside the rendering process (for example, in event handlers) are _not_ caught by error boundaries.
17+
18+
## Properties
19+
20+
For the boundary to do anything, one or both of `failed` and `onerror` must be provided.
21+
22+
### `failed`
23+
24+
If an `failed` snippet is provided, it will be rendered with the error that was thrown, and a `reset` function that recreates the contents ([demo](/playground/hello-world#H4sIAAAAAAAAE3VRy26DMBD8lS2tFCIh6JkAUlWp39Cq9EBg06CAbdlLArL87zWGKk8ORnhmd3ZnrD1WtOjFXqKO2BDGW96xqpBD5gXerm5QefG39mgQY9EIWHxueRMinLosti0UPsJLzggZKTeilLWgLGc51a3gkuCjKQ7DO7cXZotgJ3kLqzC6hmex1SZnSXTWYHcrj8LJjWTk0PHoZ8VqIdCOKayPykcpuQxAokJaG1dGybYj4gw4K5u6PKTasSbjXKgnIDlA8VvUdo-pzonraBY2bsH7HAl78mKSHZpgIcuHjq9jXSpZSLixRlveKYQUXhQVhL6GPobXAAb7BbNeyvNUs4qfRg3OnELLj5hqH9eQZqCnoBwR9lYcQxuVXeBzc8kMF8yXY4yNJ5oGiUzP_aaf_waTRGJib5_Ad3P_vbCuaYxzeNpbU0eUMPAOKh7Yw1YErgtoXyuYlPLzc10_xo_5A91zkQL_AgAA)):
25+
26+
```svelte
27+
<svelte:boundary>
28+
<FlakyComponent />
29+
30+
{#snippet failed(error, reset)}
31+
<button onclick={reset}>oops! try again</button>
32+
{/snippet}
33+
</svelte:boundary>
34+
```
35+
36+
> [!NOTE]
37+
> As with [snippets passed to components](snippet#Passing-snippets-to-components), the `failed` snippet can be passed explicitly as a property...
38+
>
39+
> ```svelte
40+
> <svelte:boundary {failed}>...</svelte:boundary>
41+
> ```
42+
>
43+
> ...or implicitly by declaring it directly inside the boundary, as in the example above.
44+
45+
### `onerror`
46+
47+
If an `onerror` function is provided, it will be called with the same two `error` and `reset` arguments. This is useful for tracking the error with an error reporting service...
48+
49+
```svelte
50+
<svelte:boundary onerror={(e) => report(e)}>
51+
...
52+
</svelte:boundary>
53+
```
54+
55+
...or using `error` and `reset` outside the boundary itself:
56+
57+
```svelte
58+
<script>
59+
let error = $state(null);
60+
let reset = $state(() => {});
61+
62+
function onerror(e, r) {
63+
error = e;
64+
reset = r;
65+
}
66+
</script>
67+
68+
<svelte:boundary {onerror}>
69+
<FlakyComponent />
70+
</svelte:boundary>
71+
72+
{#if error}
73+
<button onclick={() => {
74+
error = null;
75+
reset();
76+
}}>
77+
oops! try again
78+
</button>
79+
{/if}
80+
```
81+
82+
If an error occurs inside the `onerror` function (or if you rethrow the error), it will be handled by a parent boundary if such exists.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)