Skip to content

Commit 4d5bbc8

Browse files
authored
Merge branch 'main' into safari-safe-area
2 parents a0b4981 + 8422db4 commit 4d5bbc8

File tree

410 files changed

+8155
-3178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

410 files changed

+8155
-3178
lines changed

apps/svelte.dev/.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ SUPABASE_KEY=
33

44
GITHUB_CLIENT_ID=
55
GITHUB_CLIENT_SECRET=
6+
7+
# disable prerendering with `PRERENDER=false pnpm build` — this is useful for speeding up builds when previewing locally
8+
PRERENDER=true

apps/svelte.dev/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
/src/routes/_home/Supporters/contributors.js
77
/src/routes/_home/Supporters/donors.jpg
88
/src/routes/_home/Supporters/donors.js
9+
/scripts/svelte-template
10+
/static/svelte-template.json
911

1012
# git-repositories of synced docs go here
1113
/repos/

apps/svelte.dev/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ When writing content for the tutorial, you need to be aware of the differences o
3535
### Dependencies
3636

3737
If you look in the site's package.json you'll notice several dependencies that don't appear to be used, such as `@testing-library/svelte`. These are present because they're referenced in the docs, and Twoslash needs to be able to find type definitions in order to typecheck snippets. Installing the dependencies was deemed preferable to faking it with `declare module`, since we're liable to end up with fictional types that way.
38+
39+
### Prerendering
40+
41+
Most of the site is prerendered. Since that involves some fairly expensive work, it can take a while. To build the site _without_ prerendering — for example, because you need to debug an issue that's affecting production builds — set the `PRERENDER` environment variable to `false`:
42+
43+
```bash
44+
PRERENDER=false pnpm build
45+
```
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
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#H4sIAAAAAAAAA3WP3WrDMAyFX0VoDFqWtGRXxWsKY4-x7MKx1SbUtY2tdi0h7z7s_myD9k6c8-lIZ0Ard4QCPzqKEVong8YC172hiOJzQD75ZCcBiyv87v0sHshw0loZ6Z6unGWyHFHgUvcHUEbGWDeo0qUyX2pw1diGhyeSqoMBDNkNdwIWMBYQpN2OyX4EpJ8uQMO_J0RrpNrWwyQFwEvGpvAMr1DXNVTjajnX_WF1SZ6n5JxyG2--XUY-Gcro7M_bMJyXdR-9kScBm9Drt7OWxpJp541kKpUz-52NAgJ5kjxZFFCtw_QuG9z3I7B1QVMQUPkjRGd6DbnjxZXRk-IySO6dgCqpWZ9l6Ppsw61U201we6vFv_3cPvc-18UCmY6MgsOexq_xBw8BVaUkAgAA)
28+
29+
## Day 3: exported snippets
30+
31+
You can now export snippets from a component's `<script module>`, for use in other components, as long as those snippets don't reference anything belonging to the component instance.
32+
33+
- [docs](/docs/svelte/snippet#Exporting-snippets)
34+
- [demo](/playground/16b7dd7105c248e59ec8a437697f588d)
35+
36+
## Day 4: form control default values
37+
38+
When you reset a form, the value of each `<input>` element reverts to its `defaultValue`. This is normally the empty string, but you can now control it directly in your template.
39+
40+
- [docs](/docs/svelte/bind#input-bind:value)
41+
- [demo](/playground/b30cfac16c3c4a3ab3d76ad20a5925cf)
42+
43+
## Day 5: `MediaQuery`, `prefersReducedMotion` and `createSubscriber`
44+
45+
It's a three-in-one kind of day. `new MediaQuery(...)` gives you an object with a reactive `current` property that's true when the media query matches. `prefersReducedMotion` is an instance of `MediaQuery` that matches if the user has expressed a [preference for reduced motion](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion), helping you build accessible apps. Under the hood, both are using the `createSubscriber` mechanism, which gives you an easy way to set up event listeners when a value is read inside an effect.
46+
47+
- [`createSubscriber` docs](/docs/svelte/svelte-reactivity#createSubscriber)
48+
- [`MediaQuery` docs](/docs/svelte/svelte-reactivity#MediaQuery)
49+
- [`prefersReducedMotion` docs](/docs/svelte/svelte-motion#prefersReducedMotion)
50+
- [demo](/playground/89f6f3bb738149fcb6e708cfce878e0f)
51+
52+
## Day 6: `Spring` and `Tween`
53+
54+
We now have modern state-based alternatives to the `spring` and `tweened` stores of old. Smooth!
55+
56+
- [`Tween` tutorial](/tutorial/svelte/tweens)
57+
- [`Spring` tutorial](/tutorial/svelte/springs)
58+
- [docs](/docs/svelte/svelte-motion)
59+
- [demo](/playground/8a021b2ec2064230bde4a10b08464876?version=5.8.0)
60+
61+
## Day 7: better tutorial navigation
62+
63+
A lot of you disliked the dropdown navigation for the tutorial — essentially a giant, unwieldy `<select>` element — so we've replaced it with a hierarchical menu. Because it's all just `<details>` and `<a>` elements, we get accessibility features for free. You can even navigate the tutorial with JavaScript disabled!
64+
65+
- [tutorial](/tutorial/svelte/welcome-to-svelte)
66+
67+
## Day 8: function bindings
68+
69+
You can now do `bind:value={get, set}` to validate and transform bound values. This works for all bindings, even on components.
70+
71+
- [docs](/docs/svelte/bind#Function-bindings)
72+
- [demo](/playground/1ddd82f573b94201b3c8fcab33bf0a46?version=5.9.0)
73+
74+
## Day 9: error and warning documentation
75+
76+
When Svelte emits a warning or error (whether at build time, when the compiler is running, or when the app is running on the server or in the browser) it will now be accompanied by a link to the corresponding entry in the documentation containing a description (which is omitted from production builds, to save bytes) and — in some cases, with more to come — more details on why it happened and what you can do to fix it.
77+
78+
- [demo](/playground/8095884c1f5040ea846669b904083e25?version=5.10.0)
79+
80+
## Day 10: SvelteKit `init` hooks
81+
82+
A lot of you wanted a place to put asynchronous setup work that happens before your SvelteKit app starts up. You can now export an `init` function from `hooks.server.js` and `hooks.client.js` that will be awaited before any other stuff happens.
83+
84+
- [docs](/docs/kit/hooks#Shared-hooks-init)
85+
86+
## Day 11: `svelte/reactivity/window`
87+
88+
Today we added a whole new module. `svelte/reactivity/window` exports a variety of reactive values like `innerWidth`, `innerHeight`, `scrollX`, `scrollY` and so on. Like the `MediaQuery` introduced on day 5 and `Spring` and `Tween` from day 6, these are class instances with a reactive `current` property that you can use in your template and in deriveds/effects. Behind the scenes, Svelte handles all the event listener stuff.
89+
90+
- [docs](/docs/svelte/svelte-reactivity-window)
91+
- [demo](/playground/8ac86e10fdce485a99c29c95e0092df4?version=5.11.0)
92+
93+
## Day 12: custom type transport in SvelteKit
94+
95+
A `load` function that runs on the server in your SvelteKit app isn't restricted to returning things that can be serialized as JSON. You can return Maps, Sets, Dates, objects with cyclical references, even Promises, and SvelteKit will handle the serialization on the server and deserialization in the browser.
96+
97+
As of today, you can also return things that _aren't_ built in to the language, such as [classes containing state](/docs/svelte/$state#Classes), or classes returned by your database ORM library, or whatever — just export a `transport` object from your `hooks.js` that provides an `encode` and `decode` function.
98+
99+
- [docs](/docs/kit/hooks#Universal-hooks-transport)
100+
- [demo](https://stackblitz.com/edit/sveltejs-kit-template-default-b5zbxomg?file=src%2Fhooks.js)
101+
102+
## Day 13: rise of the robots
103+
104+
For those of you using LLMs to help you write code — via Cursor or Copilot or Claude or Bolt or v0 or some other interface — we now publish the documentation in a selection of robot-friendly `llms.txt` files. This is experimental and will evolve over time, but by way of example here's a [snake game](/playground/0de3c1c1a31d47bdbb7c4aa3477a6b46) built by Sonnet 3.5 with no additional prompting.
105+
106+
Thanks to [Didier Catz](https://x.com/didiercatz) and [Stanislav Khromov](https://bsky.app/profile/khromov.se) for building this!
107+
108+
- [docs](/docs/llms)
109+
110+
## Day 14: unmount with outros
111+
112+
Now, if you need to programmatically mount and unmount a component, you can now pass an `outro: true` option to `unmount` to play transitions before it is removed from the DOM.
113+
114+
- [docs](/docs/svelte/imperative-component-api#unmount)
115+
- [demo](/playground/a4ca332691204ccd887ec7b1df818182?version=5.13.0)
116+
117+
## Day 15: debugging superpowers
118+
119+
The new `$inspect.trace(...)` rune gives you detailed information about which state changes caused a derived or effect to re-run.
120+
121+
- [docs](</docs/svelte/$inspect#$inspect.trace()>)
122+
- [demo](/playground/d135c6f00beb4fa391725e59d8061604?version=5.14.0)
123+
124+
## Day 16: `$app/state`
125+
126+
SvelteKit's `$app/stores` module, which gives you a way to access information about (for example) the current page, now has a modern Svelte 5 state-based counterpart: `$app/state`. It exposes all the same information, but using fine-grained state, and without the clunky `$` prefix. `$app/stores` is now deprecated, and will be removed in SvelteKit 3 next year.
127+
128+
You can migrate automatically by running the following command in your SvelteKit app:
129+
130+
```bash
131+
npx sv migrate app-state
132+
```
133+
134+
- [docs](/docs/kit/$app-state)
135+
- [tutorial](/tutorial/kit/page-state)
136+
137+
## Day 17: better IntelliSense
138+
139+
The parser used by the language tools that power things like the [Svelte for VS Code](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) extension is the same one used by the Svelte compiler. Until today, it would fail if it encountered a syntax error, making it hard to provide things like autocomplete while you were in the middle of writing code.
140+
141+
We just fixed that. Install the latest version of Svelte in your project, make sure your extensions are up to date, and feel the wind in your hair as you write your components.
142+
143+
- [demo video](https://bsky.app/profile/svelte.dev/post/3ldjajjbkwc2n)
144+
145+
## Day 18: playground hovers
146+
147+
If you've ever wondered how the Svelte compiler works, today's update is for you. If you go to the [playground](/playground) and open the AST output tab, you'll see the abstract syntax tree that the compiler operates on. As of today, hovering over code in the editor will highlight the corresponding section of the AST and vice versa. Clicking on a piece of code will expand the tree and scroll to the AST.
148+
149+
The JS and CSS output tabs have also been upgraded — they now use sourcemaps to highlight the output code that corresponds to a given piece input, where applicable, and vice versa. We plan to use this to improve the sourcemaps themselves, which over time will result in smoother debugging when you're building Svelte apps.
150+
151+
- [playground](/playground)
152+
- [demo video](https://bsky.app/profile/svelte.dev/post/3ldlkmce6oc2j)
153+
154+
## Day 19: single-file SvelteKit bundles
155+
156+
By default, SvelteKit uses a technique called _code-splitting_ so that you only load the JavaScript and CSS you need for the page you're currently on. This helps make sure your app loads fast even if it grows very large.
157+
158+
In [some situations](https://github.com/sveltejs/kit/issues/3882), code-splitting is unhelpful — what you really want is a single .js file and a single .css file for your entire app. SvelteKit now supports this with the `output.bundleStrategy` option.
159+
160+
- [docs](/docs/kit/configuration#output)
161+
- [example](https://bsky.app/profile/svelte.dev/post/3ldo633ht222p)
162+
163+
## Day 20: Vim mode
164+
165+
The [playground](/playground) had a secret Vim mode that you could activate by appending `?vim=true` to the URL, but it was buggy. We've fixed it, and added a toggle to the playground and the tutorial that remembers your preference between visits. But don't worry: unlike normal Vim, you can quit by turning it off again (or closing the tab).
166+
167+
- [playground](/playground)
168+
- [tutorial](/tutorial)
169+
- [demo video](https://bsky.app/profile/svelte.dev/post/3ldqli3lk4k2g)
170+
171+
## Day 21: hash-based routing
172+
173+
SvelteKit now supports hash-based routing, in addition to the default pathname-based routing. This can be useful for purely client-side apps (including those you might build with Electron or Tauri), or situations where you don't control the webserver and need to put everything on a single page.
174+
175+
It comes with caveats — you can't use server-rendering (or any server logic), and you need to make sure all your internal links start with `/#/` or they won't work. Other than, it's just like any other SvelteKit app.
176+
177+
- [docs](/docs/kit/configuration#router)
178+
- [demo](https://hash-based-routing.vercel.app/)
179+
180+
## Day 22: self-contained apps
181+
182+
Following the introduction of the `bundleStrategy` option on day 19, and hash-based routing yesterday, we now have the ability to generate fully self-contained apps with the `bundleStrategy: 'inline'` option. Together with Vite's `assetsInlineLimit` option, it's possible to put an entire SvelteKit app — code, styles, fonts, images, audio and everything else — inside a single .html file that you can share with people on a floppy disk.
183+
184+
- [docs](/docs/kit/configuration#output)
185+
- [example downloadable Snake game](https://svelte-snek.vercel.app/)
186+
187+
## Day 23: download from playground
188+
189+
We've added a 'download app' option to the toolbox in the playground — selecting it will zip up the app, along with any packages you've imported, and download it to your machine so you can continue working on it in your editor of choice.
190+
191+
- [playground](/playground)
192+
193+
## Day 24: clsx built in
194+
195+
Svelte now uses [clsx](https://github.com/lukeed/clsx) to parse `class` attributes, meaning you can use objects and arrays to conditionally add and remove classes. It's much more powerful and flexible than the `class:` directive, and — since this is Svelte — you still get dead code elimination of unused CSS. This feature is particularly useful for all you Tailwind-heads.
196+
197+
- [docs](/docs/svelte/class)
198+
- [tutorial](/tutorial/svelte/classes)
199+
- [demo](/playground/61450f09983046efb18273d5c94db7b4?version=5.16.0)
200+
201+
---
202+
203+
And that's a wrap! Thanks for following along, everyone, and Merry Christmas to all who celebrate.

0 commit comments

Comments
 (0)