Skip to content

Commit a8cff16

Browse files
Sync kit docs (#998)
sync kit docs Co-authored-by: Rich-Harris <[email protected]>
1 parent 65825d3 commit a8cff16

File tree

7 files changed

+97
-6
lines changed

7 files changed

+97
-6
lines changed

apps/svelte.dev/content/docs/kit/20-core-concepts/10-routing.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Pages can receive data from `load` functions via the `data` prop.
5454
> [!LEGACY]
5555
> In Svelte 4, you'd use `export let data` instead
5656
57-
> [!NOTE] Note that SvelteKit uses `<a>` elements to navigate between routes, rather than a framework-specific `<Link>` component.
57+
> [!NOTE] SvelteKit uses `<a>` elements to navigate between routes, rather than a framework-specific `<Link>` component.
5858
5959
### +page.js
6060

@@ -303,6 +303,8 @@ If an error is thrown (either `error(...)` or an unexpected error), the response
303303
304304
> [!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.
305305
306+
> [!NOTE] `+layout` files have no effect on `+server.js` files. If you want to run some logic before each request, add it to the server [`handle`](hooks#Server-hooks-handle) hook.
307+
306308
### Receiving data
307309
308310
By exporting `POST`/`PUT`/`PATCH`/`DELETE`/`OPTIONS`/`HEAD` handlers, `+server.js` files can be used to create a complete API:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ export default {
3535

3636
### config
3737

38-
Path to your custom `wrangler.toml` config file.
38+
Path to your custom `wrangler.toml` or `wrangler.json` config file.
3939

4040
### platformProxy
4141

4242
Preferences for the emulated `platform.env` local bindings. See the [getPlatformProxy](https://developers.cloudflare.com/workers/wrangler/api/#syntax) Wrangler API documentation for a full list of options.
4343

4444
## Basic Configuration
4545

46-
This adapter expects to find a [wrangler.toml](https://developers.cloudflare.com/workers/platform/sites/configuration) file in the project root. It should look something like this:
46+
This adapter expects to find a [wrangler.toml/wrangler.json](https://developers.cloudflare.com/workers/platform/sites/configuration) file in the project root. It should look something like this:
4747

4848
```toml
4949
/// file: wrangler.toml

apps/svelte.dev/content/docs/kit/25-build-and-deploy/80-adapter-netlify.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,6 @@ Additionally, you can add your own Netlify functions by creating a directory for
114114

115115
You can't use `fs` in edge deployments.
116116

117-
You _can_ use it in serverless deployments, but it won't work as expected, since files are not copied from your project into your deployment. Instead, use the `read` function from `$app/server` to access your files. `read` does not work inside edge deployments (this may change in future).
117+
You _can_ use it in serverless deployments, but it won't work as expected, since files are not copied from your project into your deployment. Instead, use the [`read`]($app-server#read) function from `$app/server` to access your files. `read` does not work inside edge deployments (this may change in future).
118118

119119
Alternatively, you can [prerender](page-options#prerender) the routes in question.

apps/svelte.dev/content/docs/kit/25-build-and-deploy/90-adapter-vercel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,6 @@ Projects created before a certain date may default to using an older Node versio
174174

175175
You can't use `fs` in edge functions.
176176

177-
You _can_ use it in serverless functions, but it won't work as expected, since files are not copied from your project into your deployment. Instead, use the `read` function from `$app/server` to access your files. `read` does not work inside routes deployed as edge functions (this may change in future).
177+
You _can_ use it in serverless functions, but it won't work as expected, since files are not copied from your project into your deployment. Instead, use the [`read`]($app-server#read) function from `$app/server` to access your files. `read` does not work inside routes deployed as edge functions (this may change in future).
178178

179179
Alternatively, you can [prerender](page-options#prerender) the routes in question.

apps/svelte.dev/content/docs/kit/30-advanced/20-hooks.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,23 @@ The `lang` parameter will be correctly derived from the returned pathname.
291291

292292
Using `reroute` will _not_ change the contents of the browser's address bar, or the value of `event.url`.
293293

294+
### transport
295+
296+
This is a collection of _transporters_, which allow you to pass custom types — returned from `load` and form actions — across the server/client boundary. Each transporter contains an `encode` function, which encodes values on the server (or returns `false` for anything that isn't an instance of the type) and a corresponding `decode` function:
297+
298+
```js
299+
/// file: src/hooks.js
300+
import { Vector } from '$lib/math';
301+
302+
/** @type {import('@sveltejs/kit').Transport} */
303+
export const transport = {
304+
Vector: {
305+
encode: (value) => value instanceof Vector && [value.x, value.y],
306+
decode: ([x, y]) => new Vector(x, y)
307+
}
308+
};
309+
```
310+
294311

295312
## Further reading
296313

apps/svelte.dev/content/docs/kit/30-advanced/50-server-only-modules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The [`$env/static/private`]($env-static-private) and [`$env/dynamic/private`]($e
1111

1212
## Server-only utilities
1313

14-
The [`$app/server`]($app-server) module, which contains a `read` function for reading assets from the filesystem, can likewise only be imported by code that runs on the server.
14+
The [`$app/server`]($app-server) module, which contains a [`read`]($app-server#read) function for reading assets from the filesystem, can likewise only be imported by code that runs on the server.
1515

1616
## Your modules
1717

apps/svelte.dev/content/docs/kit/98-reference/[email protected]

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,6 +2619,78 @@ type SubmitFunction<
26192619

26202620
</div>
26212621

2622+
## Transport
2623+
2624+
<blockquote class="since note">
2625+
2626+
Available since 2.11.0
2627+
2628+
</blockquote>
2629+
2630+
The [`transport`](/docs/kit/hooks#Universal-hooks-transport) hook allows you to transport custom types across the server/client boundary.
2631+
2632+
Each transporter has a pair of `encode` and `decode` functions. On the server, `encode` determines whether a value is an instance of the custom type and, if so, returns a non-falsy encoding of the value which can be an object or an array (or `false` otherwise).
2633+
2634+
In the browser, `decode` turns the encoding back into an instance of the custom type.
2635+
2636+
```ts
2637+
import type { Transport } from '@sveltejs/kit';
2638+
2639+
declare class MyCustomType {
2640+
data: any
2641+
}
2642+
2643+
// hooks.js
2644+
export const transport: Transport = {
2645+
MyCustomType: {
2646+
encode: (value) => value instanceof MyCustomType && [value.data],
2647+
decode: ([data]) => new MyCustomType(data)
2648+
}
2649+
};
2650+
```
2651+
2652+
<div class="ts-block">
2653+
2654+
```dts
2655+
type Transport = Record<string, Transporter>;
2656+
```
2657+
2658+
</div>
2659+
2660+
## Transporter
2661+
2662+
A member of the [`transport`](/docs/kit/hooks#Universal-hooks-transport) hook.
2663+
2664+
<div class="ts-block">
2665+
2666+
```dts
2667+
interface Transporter<
2668+
T = any,
2669+
U = Exclude<
2670+
any,
2671+
false | 0 | '' | null | undefined | typeof NaN
2672+
>
2673+
> {/*…*/}
2674+
```
2675+
2676+
<div class="ts-block-property">
2677+
2678+
```dts
2679+
encode: (value: T) => false | U;
2680+
```
2681+
2682+
<div class="ts-block-property-details"></div>
2683+
</div>
2684+
2685+
<div class="ts-block-property">
2686+
2687+
```dts
2688+
decode: (data: U) => T;
2689+
```
2690+
2691+
<div class="ts-block-property-details"></div>
2692+
</div></div>
2693+
26222694

26232695

26242696
## Private types

0 commit comments

Comments
 (0)