Skip to content

Commit 28085de

Browse files
authored
site: sync to current svelte.dev (#10187)
1 parent 737eb67 commit 28085de

Some content is hidden

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

60 files changed

+2094
-2911
lines changed

documentation/docs/20-core-concepts/10-routing.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ Each route directory contains one or more _route files_, which can be identified
1919
A `+page.svelte` component defines a page of your app. By default, pages are rendered both on the server ([SSR](glossary#ssr)) for the initial request and in the browser ([CSR](glossary#csr)) for subsequent navigation.
2020

2121
```svelte
22-
/// file: src/routes/+page.svelte
22+
<!--- file: src/routes/+page.svelte --->
2323
<h1>Hello and welcome to my site!</h1>
2424
<a href="/about">About my site</a>
2525
```
2626

2727
```svelte
28-
/// file: src/routes/about/+page.svelte
28+
<!--- file: src/routes/about/+page.svelte --->
2929
<h1>About this site</h1>
3030
<p>TODO...</p>
3131
<a href="/">Home</a>
3232
```
3333

3434
```svelte
35-
/// file: src/routes/blog/[slug]/+page.svelte
35+
<!--- file: src/routes/blog/[slug]/+page.svelte --->
3636
<script>
3737
/** @type {import('./$types').PageData} */
3838
export let data;
@@ -119,7 +119,7 @@ A `+page.server.js` file can also export _actions_. If `load` lets you read data
119119
If an error occurs during `load`, SvelteKit will render a default error page. You can customise this error page on a per-route basis by adding an `+error.svelte` file:
120120

121121
```svelte
122-
/// file: src/routes/blog/[slug]/+error.svelte
122+
<!--- file: src/routes/blog/[slug]/+error.svelte --->
123123
<script>
124124
import { page } from '$app/stores';
125125
</script>
@@ -188,7 +188,7 @@ Layouts can be _nested_. Suppose we don't just have a single `/settings` page, b
188188
We can create a layout that only applies to pages below `/settings` (while inheriting the root layout with the top-level nav):
189189

190190
```svelte
191-
/// file: src/routes/settings/+layout.svelte
191+
<!--- file: src/routes/settings/+layout.svelte --->
192192
<script>
193193
/** @type {import('./$types').LayoutData} */
194194
export let data;
@@ -229,7 +229,7 @@ If a `+layout.js` exports [page options](page-options) — `prerender`, `ssr` an
229229
Data returned from a layout's `load` function is also available to all its child pages:
230230

231231
```svelte
232-
/// file: src/routes/settings/profile/+page.svelte
232+
<!--- file: src/routes/settings/profile/+page.svelte --->
233233
<script>
234234
/** @type {import('./$types').PageData} */
235235
export let data;
@@ -286,7 +286,7 @@ If an error is thrown (either `throw error(...)` or an unexpected error), the re
286286
By exporting `POST`/`PUT`/`PATCH`/`DELETE`/`OPTIONS`/`HEAD` handlers, `+server.js` files can be used to create a complete API:
287287
288288
```svelte
289-
/// file: src/routes/add/+page.svelte
289+
<!--- file: src/routes/add/+page.svelte --->
290290
<script>
291291
let a = 0;
292292
let b = 0;
@@ -340,7 +340,7 @@ Throughout the examples above, we've been importing types from a `$types.d.ts` f
340340
For example, annotating `export let data` with `PageData` (or `LayoutData`, for a `+layout.svelte` file) tells TypeScript that the type of `data` is whatever was returned from `load`:
341341
342342
```svelte
343-
/// file: src/routes/blog/[slug]/+page.svelte
343+
<!--- file: src/routes/blog/[slug]/+page.svelte --->
344344
<script>
345345
/** @type {import('./$types').PageData} */
346346
export let data;

documentation/docs/20-core-concepts/20-load.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function load({ params }) {
2222
```
2323

2424
```svelte
25-
/// file: src/routes/blog/[slug]/+page.svelte
25+
<!--- file: src/routes/blog/[slug]/+page.svelte --->
2626
<script>
2727
/** @type {import('./$types').PageData} */
2828
export let data;
@@ -83,7 +83,7 @@ export async function load() {
8383
```
8484

8585
```svelte
86-
/// file: src/routes/blog/[slug]/+layout.svelte
86+
<!--- file: src/routes/blog/[slug]/+layout.svelte --->
8787
<script>
8888
/** @type {import('./$types').LayoutData} */
8989
export let data;
@@ -141,7 +141,7 @@ The `+page.svelte` component, and each `+layout.svelte` component above it, has
141141
In some cases, we might need the opposite — a parent layout might need to access page data or data from a child layout. For example, the root layout might want to access a `title` property returned from a `load` function in `+page.js` or `+page.server.js`. This can be done with `$page.data`:
142142

143143
```svelte
144-
/// file: src/routes/+layout.svelte
144+
<!--- file: src/routes/+layout.svelte --->
145145
<script>
146146
import { page } from '$app/stores';
147147
</script>
@@ -341,7 +341,7 @@ export async function load({ parent }) {
341341
```
342342

343343
```svelte
344-
/// file: src/routes/abc/+page.svelte
344+
<!--- file: src/routes/abc/+page.svelte --->
345345
<script>
346346
/** @type {import('./$types').PageData} */
347347
export let data;
@@ -464,7 +464,7 @@ export function load() {
464464
This is useful for creating skeleton loading states, for example:
465465

466466
```svelte
467-
/// file: src/routes/+page.svelte
467+
<!--- file: src/routes/+page.svelte --->
468468
<script>
469469
/** @type {import('./$types').PageData} */
470470
export let data;
@@ -569,7 +569,7 @@ export async function load({ fetch, depends }) {
569569
```
570570

571571
```svelte
572-
/// file: src/routes/random-number/+page.svelte
572+
<!--- file: src/routes/random-number/+page.svelte --->
573573
<script>
574574
import { invalidate, invalidateAll } from '$app/navigation';
575575

documentation/docs/20-core-concepts/30-form-actions.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const actions = {
2323
To invoke this action from the `/login` page, just add a `<form>` — no JavaScript needed:
2424

2525
```svelte
26-
/// file: src/routes/login/+page.svelte
26+
<!--- file: src/routes/login/+page.svelte --->
2727
<form method="POST">
2828
<label>
2929
Email
@@ -71,12 +71,12 @@ export const actions = {
7171
To invoke a named action, add a query parameter with the name prefixed by a `/` character:
7272

7373
```svelte
74-
/// file: src/routes/login/+page.svelte
74+
<!--- file: src/routes/login/+page.svelte --->
7575
<form method="POST" action="?/register">
7676
```
7777

7878
```svelte
79-
/// file: src/routes/+layout.svelte
79+
<!--- file: src/routes/+layout.svelte --->
8080
<form method="POST" action="/login?/register">
8181
```
8282

@@ -133,7 +133,7 @@ export const actions = {
133133
```
134134

135135
```svelte
136-
/// file: src/routes/login/+page.svelte
136+
<!--- file: src/routes/login/+page.svelte --->
137137
<script>
138138
/** @type {import('./$types').PageData} */
139139
export let data;
@@ -401,7 +401,7 @@ In all cases, [focus will be reset](accessibility#focus-management).
401401
We can also implement progressive enhancement ourselves, without `use:enhance`, with a normal event listener on the `<form>`:
402402

403403
```svelte
404-
/// file: src/routes/login/+page.svelte
404+
<!--- file: src/routes/login/+page.svelte --->
405405
<script>
406406
import { invalidateAll, goto } from '$app/navigation';
407407
import { applyAction, deserialize } from '$app/forms';
@@ -456,7 +456,7 @@ const response = await fetch(this.action, {
456456
Form actions are the preferred way to send data to the server, since they can be progressively enhanced, but you can also use [`+server.js`](routing#server) files to expose (for example) a JSON API. Here's how such an interaction could look like:
457457

458458
```svelte
459-
/// file: send-message/+page.svelte
459+
<!--- file: send-message/+page.svelte --->
460460
<script>
461461
function rerun() {
462462
fetch('/api/ci', {
@@ -469,7 +469,7 @@ Form actions are the preferred way to send data to the server, since they can be
469469
```
470470

471471
```js
472-
// @errors: 2355 1360
472+
// @errors: 2355 1360 2322
473473
/// file: api/ci/+server.js
474474

475475
/** @type {import('./$types').RequestHandler} */

documentation/docs/20-core-concepts/50-state-management.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ If you're not using SSR, then there's no risk of accidentally exposing one user'
8484
You might wonder how we're able to use `$page.data` and other [app stores](modules#$app-stores) if we can't use our own stores. The answer is that app stores on the server use Svelte's [context API](https://learn.svelte.dev/tutorial/context-api) — the store is attached to the component tree with `setContext`, and when you subscribe you retrieve it with `getContext`. We can do the same thing with our own stores:
8585

8686
```svelte
87-
/// file: src/routes/+layout.svelte
87+
<!--- file: src/routes/+layout.svelte --->
8888
<script>
8989
import { setContext } from 'svelte';
9090
import { writable } from 'svelte/store';
@@ -102,7 +102,7 @@ You might wonder how we're able to use `$page.data` and other [app stores](modul
102102
```
103103

104104
```svelte
105-
/// file: src/routes/user/+page.svelte
105+
<!--- file: src/routes/user/+page.svelte --->
106106
<script>
107107
import { getContext } from 'svelte';
108108
@@ -122,7 +122,7 @@ If you're not using SSR (and can guarantee that you won't need to use SSR in fut
122122
When you navigate around your application, SvelteKit reuses existing layout and page components. For example, if you have a route like this...
123123

124124
```svelte
125-
/// file: src/routes/blog/[slug]/+page.svelte
125+
<!--- file: src/routes/blog/[slug]/+page.svelte --->
126126
<script>
127127
/** @type {import('./$types').PageData} */
128128
export let data;

documentation/docs/25-build-and-deploy/90-adapter-vercel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export function load() {
120120
```
121121

122122
```svelte
123-
/// file: +layout.svelte
123+
<!--- file: +layout.svelte --->
124124
<script>
125125
/** @type {import('./$types').LayoutServerData} */
126126
export let data;

documentation/docs/30-advanced/10-advanced-routing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ src/routes/
254254
Not all use cases are suited for layout grouping, nor should you feel compelled to use them. It might be that your use case would result in complex `(group)` nesting, or that you don't want to introduce a `(group)` for a single outlier. It's perfectly fine to use other means such as composition (reusable `load` functions or Svelte components) or if-statements to achieve what you want. The following example shows a layout that rewinds to the root layout and reuses components and functions that other layouts can also use:
255255

256256
```svelte
257-
/// file: src/routes/nested/route/[email protected]
257+
<!--- file: src/routes/nested/route/[email protected] --->
258258
<script>
259259
import ReusableLayout from '$lib/ReusableLayout.svelte';
260260
export let data;

documentation/docs/30-advanced/25-errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function load({ params }) {
4343
This tells SvelteKit to set the response status code to 404 and render an [`+error.svelte`](routing#error) component, where `$page.error` is the object provided as the second argument to `error(...)`.
4444

4545
```svelte
46-
/// file: src/routes/+error.svelte
46+
<!--- file: src/routes/+error.svelte --->
4747
<script>
4848
import { page } from '$app/stores';
4949
</script>

documentation/docs/30-advanced/65-snapshots.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ For example, if the user fills out a form but clicks a link before submitting, t
99
To do this, export a `snapshot` object with `capture` and `restore` methods from a `+page.svelte` or `+layout.svelte`:
1010

1111
```svelte
12-
/// file: +page.svelte
12+
<!--- file: +page.svelte --->
1313
<script>
1414
let comment = '';
1515

documentation/docs/40-best-practices/10-accessibility.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Since navigation between pages in SvelteKit happens without reloading the page (
1717
Because of this behavior, every page in your app should have a unique, descriptive title. In SvelteKit, you can do this by placing a `<svelte:head>` element on each page:
1818

1919
```svelte
20-
/// file: src/routes/+page.svelte
20+
<!--- file: src/routes/+page.svelte --->
2121
<svelte:head>
2222
<title>Todo List</title>
2323
</svelte:head>

documentation/docs/50-reference/40-types.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ The `RequestHandler` and `Load` types both accept a `Params` argument allowing y
2222
/// file: src/routes/[foo]/[bar]/[baz]/+page.server.js
2323
// @errors: 2355 2322 1360
2424
/** @type {import('@sveltejs/kit').RequestHandler<{
25-
* foo: string;
26-
* bar: string;
27-
* baz: string
28-
* }>} */
25+
foo: string;
26+
bar: string;
27+
baz: string
28+
}>} */
2929
export async function GET({ params }) {
3030
// ...
3131
}
@@ -98,7 +98,7 @@ export async function load({ params, fetch }) {
9898

9999
> For this to work, your own `tsconfig.json` or `jsconfig.json` should extend from the generated `.svelte-kit/tsconfig.json` (where `.svelte-kit` is your [`outDir`](configuration#outdir)):
100100
>
101-
> { "extends": "./.svelte-kit/tsconfig.json" }
101+
> `{ "extends": "./.svelte-kit/tsconfig.json" }`
102102
103103
### Default tsconfig.json
104104

0 commit comments

Comments
 (0)