Skip to content

Commit 0f96cdd

Browse files
sync docs from kit and svelte repos (#550)
Co-authored-by: Ben McCann <[email protected]>
1 parent 0a5faa3 commit 0f96cdd

Some content is hidden

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

50 files changed

+218
-167
lines changed

apps/svelte.dev/content/docs/kit/10-getting-started/10-introduction.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ title: Introduction
44

55
## Before we begin
66

7-
> [!NOTE] If you're new to Svelte or SvelteKit we recommend checking out the [interactive tutorial](https://learn.svelte.dev).
7+
> [!NOTE] If you're new to Svelte or SvelteKit we recommend checking out the [interactive tutorial](/tutorial/kit).
88
>
99
> If you get stuck, reach out for help in the [Discord chatroom](https://svelte.dev/chat).
1010
1111
## What is SvelteKit?
1212

13-
SvelteKit is a framework for rapidly developing robust, performant web applications using [Svelte](https://svelte.dev/). If you're coming from React, SvelteKit is similar to Next. If you're coming from Vue, SvelteKit is similar to Nuxt.
13+
SvelteKit is a framework for rapidly developing robust, performant web applications using [Svelte](../svelte). If you're coming from React, SvelteKit is similar to Next. If you're coming from Vue, SvelteKit is similar to Nuxt.
1414

1515
To learn more about the kinds of applications you can build with SvelteKit, see the [FAQ](faq#What-can-I-make-with-SvelteKit).
1616

1717
## What is Svelte?
1818

19-
In short, Svelte is a way of writing user interface components — like a navigation bar, comment section, or contact form — that users see and interact with in their browsers. The Svelte compiler converts your components to JavaScript that can be run to render the HTML for the page and to CSS that styles the page. You don't need to know Svelte to understand the rest of this guide, but it will help. If you'd like to learn more, check out [the Svelte tutorial](https://svelte.dev/tutorial).
19+
In short, Svelte is a way of writing user interface components — like a navigation bar, comment section, or contact form — that users see and interact with in their browsers. The Svelte compiler converts your components to JavaScript that can be run to render the HTML for the page and to CSS that styles the page. You don't need to know Svelte to understand the rest of this guide, but it will help. If you'd like to learn more, check out [the Svelte tutorial](/tutorial).
2020

2121
## SvelteKit vs Svelte
2222

apps/svelte.dev/content/docs/kit/10-getting-started/20-creating-a-project.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The first command will scaffold a new project in the `my-app` directory asking y
1515

1616
There are two basic concepts:
1717

18-
- Each page of your app is a [Svelte](https://svelte.dev) component
18+
- Each page of your app is a [Svelte](../svelte) component
1919
- You create pages by adding files to the `src/routes` directory of your project. These will be server-rendered so that a user's first visit to your app is as fast as possible, then a client-side app takes over
2020

2121
Try editing the files to get a feel for how everything works.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ In turn, annotating the `load` function with `PageLoad`, `PageServerLoad`, `Layo
384384
385385
If you're using VS Code or any IDE that supports the language server protocol and TypeScript plugins then you can omit these types _entirely_! Svelte's IDE tooling will insert the correct types for you, so you'll get type checking without writing them yourself. It also works with our command line tool `svelte-check`.
386386
387-
You can read more about omitting `$types` in our [blog post](https://svelte.dev/blog/zero-config-type-safety) about it.
387+
You can read more about omitting `$types` in our [blog post](/blog/zero-config-type-safety) about it.
388388
389389
## Other files
390390
@@ -394,6 +394,6 @@ If components and modules are needed by multiple routes, it's a good idea to put
394394
395395
## Further reading
396396
397-
- [Tutorial: Routing](https://learn.svelte.dev/tutorial/pages)
398-
- [Tutorial: API routes](https://learn.svelte.dev/tutorial/get-handlers)
397+
- [Tutorial: Routing](/tutorial/kit/pages)
398+
- [Tutorial: API routes](/tutorial/kit/get-handlers)
399399
- [Docs: Advanced routing](advanced-routing)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function load({ params }) {
3434

3535
Thanks to the generated `$types` module, we get full type safety.
3636

37-
A `load` function in a `+page.js` file runs both on the server and in the browser (unless combined with `export const ssr = false`, in which case it will [only run in the browser](https://kit.svelte.dev/docs/page-options#ssr)). If your `load` function should _always_ run on the server (because it uses private environment variables, for example, or accesses a database) then it would go in a `+page.server.js` instead.
37+
A `load` function in a `+page.js` file runs both on the server and in the browser (unless combined with `export const ssr = false`, in which case it will [only run in the browser](page-options#ssr)). If your `load` function should _always_ run on the server (because it uses private environment variables, for example, or accesses a database) then it would go in a `+page.server.js` instead.
3838

3939
A more realistic version of your blog post's `load` function, that only runs on the server and pulls data from a database, might look like this:
4040

@@ -120,8 +120,8 @@ Data returned from layout `load` functions is available to child `+layout.svelte
120120
121121
+++ // we can access `data.posts` because it's returned from
122122
// the parent layout `load` function
123-
$: index = data.posts.findIndex(post => post.slug === $page.params.slug);
124-
$: next = data.posts[index - 1];+++
123+
let index = $derived(data.posts.findIndex(post => post.slug === $page.params.slug));
124+
let next = $derived(data.posts[index - 1];)+++
125125
</script>
126126
127127
<h1>{data.post.title}</h1>
@@ -675,7 +675,7 @@ To summarize, a `load` function will rerun in the following situations:
675675

676676
`params` and `url` can change in response to a `<a href="..">` link click, a [`<form>` interaction](form-actions#GET-vs-POST), a [`goto`]($app-navigation#goto) invocation, or a [`redirect`](@sveltejs-kit#redirect).
677677

678-
Note that rerunning a `load` function will update the `data` prop inside the corresponding `+layout.svelte` or `+page.svelte`; it does _not_ cause the component to be recreated. As a result, internal state is preserved. If this isn't what you want, you can reset whatever you need to reset inside an [`afterNavigate`]($app-navigation#afterNavigate) callback, and/or wrap your component in a [`{#key ...}`](https://svelte.dev/docs#template-syntax-key) block.
678+
Note that rerunning a `load` function will update the `data` prop inside the corresponding `+layout.svelte` or `+page.svelte`; it does _not_ cause the component to be recreated. As a result, internal state is preserved. If this isn't what you want, you can reset whatever you need to reset inside an [`afterNavigate`]($app-navigation#afterNavigate) callback, and/or wrap your component in a [`{#key ...}`](../svelte/key) block.
679679

680680
## Implications for authentication
681681

@@ -693,6 +693,6 @@ Putting an auth guard in `+layout.server.js` requires all child pages to call `a
693693

694694
## Further reading
695695

696-
- [Tutorial: Loading data](https://learn.svelte.dev/tutorial/page-data)
697-
- [Tutorial: Errors and redirects](https://learn.svelte.dev/tutorial/error-basics)
698-
- [Tutorial: Advanced loading](https://learn.svelte.dev/tutorial/await-parent)
696+
- [Tutorial: Loading data](/tutorial/kit/page-data)
697+
- [Tutorial: Errors and redirects](/tutorial/kit/error-basics)
698+
- [Tutorial: Advanced loading](/tutorial/kit/await-parent)

apps/svelte.dev/content/docs/kit/20-core-concepts/30-form-actions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,4 +518,4 @@ Submitting this form will navigate to `/search?q=...` and invoke your load funct
518518
519519
## Further reading
520520
521-
- [Tutorial: Forms](https://learn.svelte.dev/tutorial/the-form-element)
521+
- [Tutorial: Forms](/tutorial/kit/the-form-element)

apps/svelte.dev/content/docs/kit/20-core-concepts/40-page-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,4 @@ export const config = {
219219

220220
## Further reading
221221

222-
- [Tutorial: Page options](https://learn.svelte.dev/tutorial/page-options)
222+
- [Tutorial: Page options](/tutorial/kit/page-options)

apps/svelte.dev/content/docs/kit/20-core-concepts/50-state-management.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ If you're not using SSR, then there's no risk of accidentally exposing one user'
8282

8383
## Using stores with context
8484

85-
You might wonder how we're able to use `$page.data` and other [app stores]($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:
85+
You might wonder how we're able to use `$page.data` and other [app stores]($app-stores) if we can't use our own stores. The answer is that app stores on the server use Svelte's [context API](/tutorial/svelte/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:
8686

8787
```svelte
8888
<!--- file: src/routes/+layout.svelte --->
@@ -143,16 +143,16 @@ When you navigate around your application, SvelteKit reuses existing layout and
143143

144144
...then navigating from `/blog/my-short-post` to `/blog/my-long-post` won't cause the layout, page and any other components within to be destroyed and recreated. Instead the `data` prop (and by extension `data.title` and `data.content`) will update (as it would with any other Svelte component) and, because the code isn't rerunning, lifecycle methods like `onMount` and `onDestroy` won't rerun and `estimatedReadingTime` won't be recalculated.
145145

146-
Instead, we need to make the value [_reactive_](https://learn.svelte.dev/tutorial/reactive-assignments):
146+
Instead, we need to make the value [_reactive_](/tutorial/svelte/state):
147147

148148
```svelte
149149
/// file: src/routes/blog/[slug]/+page.svelte
150150
<script>
151151
/** @type {import('./$types').PageData} */
152152
export let data;
153153
154-
+++ $: wordCount = data.content.split(' ').length;
155-
$: estimatedReadingTime = wordCount / 250;+++
154+
+++ let wordCount = $state(data.content.split(' ').length);
155+
let estimatedReadingTime = $derived(wordCount / 250);+++
156156
</script>
157157
```
158158

apps/svelte.dev/content/docs/kit/25-build-and-deploy/30-adapter-auto.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ When you create a new SvelteKit project with `npx sv create`, it installs [`adap
99
- [`@sveltejs/adapter-vercel`](adapter-vercel) for [Vercel](https://vercel.com/)
1010
- [`svelte-adapter-azure-swa`](https://github.com/geoffrich/svelte-adapter-azure-swa) for [Azure Static Web Apps](https://docs.microsoft.com/en-us/azure/static-web-apps/)
1111
- [`svelte-kit-sst`](https://github.com/sst/sst/tree/master/packages/svelte-kit-sst) for [AWS via SST](https://sst.dev/docs/start/aws/svelte)
12-
- [`@sveltejs/adapter-node`](https://kit.svelte.dev/docs/adapter-node) for [Google Cloud Run](https://cloud.google.com/run)
12+
- [`@sveltejs/adapter-node`](adapter-node) for [Google Cloud Run](https://cloud.google.com/run)
1313

1414
It's recommended to install the appropriate adapter to your `devDependencies` once you've settled on a target environment, since this will add the adapter to your lockfile and slightly improve install times on CI.
1515

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ For testing the build, you should use [wrangler](https://developers.cloudflare.c
108108

109109
## Notes
110110

111-
Functions contained in the `/functions` directory at the project's root will _not_ be included in the deployment, which is compiled to a [single `_worker.js` file](https://developers.cloudflare.com/pages/platform/functions/#advanced-mode). Functions should be implemented as [server endpoints](https://kit.svelte.dev/docs/routing#server) in your SvelteKit app.
111+
Functions contained in the `/functions` directory at the project's root will _not_ be included in the deployment, which is compiled to a [single `_worker.js` file](https://developers.cloudflare.com/pages/platform/functions/#advanced-mode). Functions should be implemented as [server endpoints](routing#server) in your SvelteKit app.
112112

113113
The `_headers` and `_redirects` files specific to Cloudflare Pages can be used for static asset responses (like images) by putting them into the `/static` folder.
114114

115-
However, they will have no effect on responses dynamically rendered by SvelteKit, which should return custom headers or redirect responses from [server endpoints](https://kit.svelte.dev/docs/routing#server) or with the [`handle`](https://kit.svelte.dev/docs/hooks#Server-hooks-handle) hook.
115+
However, they will have no effect on responses dynamically rendered by SvelteKit, which should return custom headers or redirect responses from [server endpoints](routing#server) or with the [`handle`](hooks#Server-hooks-handle) hook.
116116

117117
## Troubleshooting
118118

@@ -122,4 +122,4 @@ You may wish to refer to [Cloudflare's documentation for deploying a SvelteKit s
122122

123123
### Accessing the file system
124124

125-
You can't use `fs` in Cloudflare Workers — you must [prerender](https://kit.svelte.dev/docs/page-options#prerender) the routes in question.
125+
You can't use `fs` in Cloudflare Workers — you must [prerender](page-options#prerender) the routes in question.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,4 @@ When deploying to workers, the server generated by SvelteKit is bundled into a s
135135

136136
### Accessing the file system
137137

138-
You can't use `fs` in Cloudflare Workers — you must [prerender](https://kit.svelte.dev/docs/page-options#prerender) the routes in question.
138+
You can't use `fs` in Cloudflare Workers — you must [prerender](page-options#prerender) the routes in question.

0 commit comments

Comments
 (0)