You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/svelte.dev/content/docs/kit/10-getting-started/40-web-standards.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ In particular, you'll get comfortable with the following:
12
12
13
13
SvelteKit uses [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch) for getting data from the network. It's available in [hooks](hooks) and [server routes](routing#server) as well as in the browser.
14
14
15
-
> A special version of `fetch` is available in [`load`](load) functions, [server hooks](hooks#server-hooks) and [API routes](routing#server) for invoking endpoints directly during server-side rendering, without making an HTTP call, while preserving credentials. (To make credentialled fetches in server-side code outside `load`, you must explicitly pass `cookie` and/or `authorization` headers.) It also allows you to make relative requests, whereas server-side `fetch` normally requires a fully qualified URL.
15
+
> [!NOTE]A special version of `fetch` is available in [`load`](load) functions, [server hooks](hooks#server-hooks) and [API routes](routing#server) for invoking endpoints directly during server-side rendering, without making an HTTP call, while preserving credentials. (To make credentialled fetches in server-side code outside `load`, you must explicitly pass `cookie` and/or `authorization` headers.) It also allows you to make relative requests, whereas server-side `fetch` normally requires a fully qualified URL.
16
16
17
17
Besides `fetch` itself, the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) includes the following interfaces:
Copy file name to clipboardExpand all lines: apps/svelte.dev/content/docs/kit/20-core-concepts/10-routing.md
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ At the heart of SvelteKit is a _filesystem-based router_. The routes of your app
8
8
-`src/routes/about` creates an `/about` route
9
9
-`src/routes/blog/[slug]` creates a route with a _parameter_, `slug`, that can be used to load data dynamically when a user requests a page like `/blog/hello-world`
10
10
11
-
> You can change `src/routes` to a different directory by editing the [project config](configuration).
11
+
> [!NOTE]You can change `src/routes` to a different directory by editing the [project config](configuration).
12
12
13
13
Each route directory contains one or more _route files_, which can be identified by their `+` prefix.
14
14
@@ -48,7 +48,7 @@ A `+page.svelte` component defines a page of your app. By default, pages are ren
48
48
<div>{@html data.content}</div>
49
49
```
50
50
51
-
> Note that SvelteKit uses `<a>` elements to navigate between routes, rather than a framework-specific `<Link>` component.
51
+
> [!NOTE]Note that SvelteKit uses `<a>` elements to navigate between routes, rather than a framework-specific `<Link>` component.
52
52
53
53
### +page.js
54
54
@@ -139,7 +139,7 @@ If the error occurs inside a `load` function in `+layout(.server).js`, the close
139
139
140
140
If no route can be found (404), `src/routes/+error.svelte` (or the default error page, if that file does not exist) will be used.
141
141
142
-
> `+error.svelte` is _not_ used when an error occurs inside [`handle`](hooks#server-hooks-handle) or a [+server.js](#server) request handler.
142
+
> [!NOTE]`+error.svelte` is _not_ used when an error occurs inside [`handle`](hooks#server-hooks-handle) or a [+server.js](#server) request handler.
143
143
144
144
You can read more about error handling [here](errors).
145
145
@@ -246,7 +246,7 @@ Data returned from a layout's `load` function is also available to all its child
246
246
</script>
247
247
```
248
248
249
-
> Often, layout data is unchanged when navigating between pages. SvelteKit will intelligently rerun [`load`](load) functions when necessary.
249
+
> [!NOTE]Often, layout data is unchanged when navigating between pages. SvelteKit will intelligently rerun [`load`](load) functions when necessary.
250
250
251
251
### +layout.server.js
252
252
@@ -287,7 +287,7 @@ You can use the [`error`](@sveltejs-kit#error), [`redirect`](@sveltejs-kit#redir
287
287
288
288
If an error is thrown (either `error(...)` or an unexpected error), the response will be a JSON representation of the error or a fallback error page — which can be customised via `src/error.html` — depending on the `Accept` header. The [`+error.svelte`](#error) component will _not_ be rendered in this case. You can read more about error handling [here](errors).
289
289
290
-
> When creating an `OPTIONS` handler, note that Vite will inject `Access-Control-Allow-Origin` and `Access-Control-Allow-Methods` headers — these will not be present in production unless you add them.
290
+
> [!NOTE] When creating an `OPTIONS` handler, note that Vite will inject `Access-Control-Allow-Origin` and `Access-Control-Allow-Methods` headers — these will not be present in production unless you add them.
Copy file name to clipboardExpand all lines: apps/svelte.dev/content/docs/kit/20-core-concepts/20-load.md
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -132,7 +132,7 @@ Data returned from layout `load` functions is available to child `+layout.svelte
132
132
+{/if}
133
133
```
134
134
135
-
> If multiple `load` functions return data with the same key, the last one 'wins' — the result of a layout `load` returning `{ a: 1, b: 2 }` and a page `load` returning `{ b: 3, c: 4 }` would be `{ a: 1, b: 3, c: 4 }`.
135
+
> [!NOTE]If multiple `load` functions return data with the same key, the last one 'wins' — the result of a layout `load` returning `{ a: 1, b: 2 }` and a page `load` returning `{ b: 3, c: 4 }` would be `{ a: 1, b: 3, c: 4 }`.
136
136
137
137
## $page.data
138
138
@@ -224,7 +224,7 @@ Often the `load` function depends on the URL in one way or another. For this, th
224
224
225
225
An instance of [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL), containing properties like the `origin`, `hostname`, `pathname` and `searchParams` (which contains the parsed query string as a [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) object). `url.hash` cannot be accessed during `load`, since it is unavailable on the server.
226
226
227
-
> In some environments this is derived from request headers during server-side rendering. If you're using [adapter-node](adapter-node), for example, you may need to configure the adapter in order for the URL to be correct.
227
+
> [!NOTE]In some environments this is derived from request headers during server-side rendering. If you're using [adapter-node](adapter-node), for example, you may need to configure the adapter in order for the URL to be correct.
> Notice that the `load` function in `+page.js` receives the merged data from both layout `load` functions, not just the immediate parent.
376
+
> [!NOTE]Notice that the `load` function in `+page.js` receives the merged data from both layout `load` functions, not just the immediate parent.
377
377
378
378
Inside `+page.server.js` and `+layout.server.js`, `parent` returns data from parent `+layout.server.js` files.
379
379
@@ -432,7 +432,7 @@ Calling `error(...)` will throw an exception, making it easy to stop execution f
432
432
433
433
If an [_unexpected_](errors#unexpected-errors) error is thrown, SvelteKit will invoke [`handleError`](hooks#shared-hooks-handleerror) and treat it as a 500 Internal Error.
434
434
435
-
> [In SvelteKit 1.x](migrating-to-sveltekit-2#redirect-and-error-are-no-longer-thrown-by-you) you had to `throw` the error yourself
435
+
> [!NOTE][In SvelteKit 1.x](migrating-to-sveltekit-2#redirect-and-error-are-no-longer-thrown-by-you) you had to `throw` the error yourself
436
436
437
437
## Redirects
438
438
@@ -461,11 +461,11 @@ export function load({ locals }) {
461
461
}
462
462
```
463
463
464
-
> Don't use `redirect()` inside a `try {...}` block, as the redirect will immediately trigger the catch statement.
464
+
> [!NOTE]Don't use `redirect()` inside a `try {...}` block, as the redirect will immediately trigger the catch statement.
465
465
466
466
In the browser, you can also navigate programmatically outside of a `load` function using [`goto`]($app-navigation#goto) from [`$app.navigation`]($app-navigation).
467
467
468
-
> [In SvelteKit 1.x](migrating-to-sveltekit-2#redirect-and-error-are-no-longer-thrown-by-you) you had to `throw` the `redirect` yourself
468
+
> [!NOTE][In SvelteKit 1.x](migrating-to-sveltekit-2#redirect-and-error-are-no-longer-thrown-by-you) you had to `throw` the `redirect` yourself
469
469
470
470
## Streaming with promises
471
471
@@ -534,13 +534,13 @@ export function load({ fetch }) {
534
534
}
535
535
```
536
536
537
-
> On platforms that do not support streaming, such as AWS Lambda or Firebase, responses will be buffered. This means the page will only render once all promises resolve. If you are using a proxy (e.g. NGINX), make sure it does not buffer responses from the proxied server.
537
+
> [!NOTE]On platforms that do not support streaming, such as AWS Lambda or Firebase, responses will be buffered. This means the page will only render once all promises resolve. If you are using a proxy (e.g. NGINX), make sure it does not buffer responses from the proxied server.
538
538
539
-
> Streaming data will only work when JavaScript is enabled. You should avoid returning promises from a universal `load` function if the page is server rendered, as these are _not_ streamed — instead, the promise is recreated when the function reruns in the browser.
539
+
> [!NOTE]Streaming data will only work when JavaScript is enabled. You should avoid returning promises from a universal `load` function if the page is server rendered, as these are _not_ streamed — instead, the promise is recreated when the function reruns in the browser.
540
540
541
-
> The headers and status code of a response cannot be changed once the response has started streaming, therefore you cannot `setHeaders` or throw redirects inside a streamed promise.
541
+
> [!NOTE]The headers and status code of a response cannot be changed once the response has started streaming, therefore you cannot `setHeaders` or throw redirects inside a streamed promise.
542
542
543
-
> [In SvelteKit 1.x](migrating-to-sveltekit-2#top-level-promises-are-no-longer-awaited) top-level promises were automatically awaited, only nested promises were streamed.
543
+
> [!NOTE][In SvelteKit 1.x](migrating-to-sveltekit-2#top-level-promises-are-no-longer-awaited) top-level promises were automatically awaited, only nested promises were streamed.
Copy file name to clipboardExpand all lines: apps/svelte.dev/content/docs/kit/20-core-concepts/30-form-actions.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ To invoke this action from the `/login` page, just add a `<form>` — no JavaScr
39
39
40
40
If someone were to click the button, the browser would send the form data via `POST` request to the server, running the default action.
41
41
42
-
> Actions always use `POST` requests, since `GET` requests should never have side-effects.
42
+
> [!NOTE]Actions always use `POST` requests, since `GET` requests should never have side-effects.
43
43
44
44
We can also invoke the action from other pages (for example if there's a login widget in the nav in the root layout) by adding the `action` attribute, pointing to the page:
45
45
@@ -99,7 +99,7 @@ As well as the `action` attribute, we can use the `formaction` attribute on a bu
99
99
</form>
100
100
```
101
101
102
-
> We can't have default actions next to named actions, because if you POST to a named action without a redirect, the query parameter is persisted in the URL, which means the next default POST would go through the named action from before.
102
+
> [!NOTE]We can't have default actions next to named actions, because if you POST to a named action without a redirect, the query parameter is persisted in the URL, which means the next default POST would go through the named action from before.
103
103
104
104
## Anatomy of an action
105
105
@@ -184,7 +184,7 @@ export const actions = {
184
184
};
185
185
```
186
186
187
-
> Note that as a precaution, we only return the email back to the page — not the password.
187
+
> [!NOTE]Note that as a precaution, we only return the email back to the page — not the password.
188
188
189
189
```diff
190
190
/// file: src/routes/login/+page.svelte
@@ -329,7 +329,7 @@ The easiest way to progressively enhance a form is to add the `use:enhance` acti
329
329
+<form method="POST" use:enhance>
330
330
```
331
331
332
-
> Yes, it's a little confusing that the `enhance` action and `<form action>` are both called 'action'. These docs are action-packed. Sorry.
332
+
> [!NOTE]Yes, it's a little confusing that the `enhance` action and `<form action>` are both called 'action'. These docs are action-packed. Sorry.
333
333
334
334
Without an argument, `use:enhance` will emulate the browser-native behaviour, just without the full-page reloads. It will:
Copy file name to clipboardExpand all lines: apps/svelte.dev/content/docs/kit/20-core-concepts/40-page-options.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ Routes with `prerender = true` will be excluded from manifests used for dynamic
31
31
exportconstprerender='auto';
32
32
```
33
33
34
-
> If your entire app is suitable for prerendering, you can use [`adapter-static`](https://github.com/sveltejs/kit/tree/main/packages/adapter-static), which will output files suitable for use with any static webserver.
34
+
> [!NOTE]If your entire app is suitable for prerendering, you can use [`adapter-static`](https://github.com/sveltejs/kit/tree/main/packages/adapter-static), which will output files suitable for use with any static webserver.
35
35
36
36
The prerenderer will start at the root of your app and generate files for any prerenderable pages or `+server.js` routes it finds. Each page is scanned for `<a>` elements that point to other pages that are candidates for prerendering — because of this, you generally don't need to specify which pages should be accessed. If you _do_ need to specify which pages should be accessed by the prerenderer, you can do so with [`config.kit.prerender.entries`](configuration#prerender), or by exporting an [`entries`](#entries) function from your dynamic route.
The basic rule is this: for a page to be prerenderable, any two users hitting it directly must get the same content from the server.
60
60
61
-
> Not all pages are suitable for prerendering. Any content that is prerendered will be seen by all users. You can of course fetch personalized data in `onMount` in a prerendered page, but this may result in a poorer user experience since it will involve blank initial content or loading indicators.
61
+
> [!NOTE]Not all pages are suitable for prerendering. Any content that is prerendered will be seen by all users. You can of course fetch personalized data in `onMount` in a prerendered page, but this may result in a poorer user experience since it will involve blank initial content or loading indicators.
62
62
63
63
Note that you can still prerender pages that load data based on the page's parameters, such as a `src/routes/blog/[slug]/+page.svelte` route.
This option also affects [prerendering](#prerender). If `trailingSlash` is `always`, a route like `/about` will result in an `about/index.html` file, otherwise it will create `about.html`, mirroring static webserver conventions.
169
169
170
-
> Ignoring trailing slashes is not recommended — the semantics of relative paths differ between the two cases (`./y` from `/x` is `/y`, but from `/x/` is `/x/y`), and `/x` and `/x/` are treated as separate URLs which is harmful to SEO.
170
+
> [!NOTE]Ignoring trailing slashes is not recommended — the semantics of relative paths differ between the two cases (`./y` from `/x` is `/y`, but from `/x/` is `/x/y`), and `/x` and `/x/` are treated as separate URLs which is harmful to SEO.
Copy file name to clipboardExpand all lines: apps/svelte.dev/content/docs/kit/20-core-concepts/50-state-management.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -155,7 +155,7 @@ Instead, we need to make the value [_reactive_](https://learn.svelte.dev/tutoria
155
155
</script>
156
156
```
157
157
158
-
> If your code in `onMount` and `onDestroy` has to run again after navigation you can use [afterNavigate]($app-navigation#afterNavigate) and [beforeNavigate]($app-navigation#beforeNavigate) respectively.
158
+
> [!NOTE]If your code in `onMount` and `onDestroy` has to run again after navigation you can use [afterNavigate]($app-navigation#afterNavigate) and [beforeNavigate]($app-navigation#beforeNavigate) respectively.
159
159
160
160
Reusing components like this means that things like sidebar scroll state are preserved, and you can easily animate between changing values. In the case that you do need to completely destroy and remount a component on navigation, you can use this pattern:
0 commit comments