From dc3d3338de8c29c740a5c581a9f3d16c6213e623 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Mon, 28 Oct 2024 10:29:36 +0100 Subject: [PATCH 1/2] docs: sync repos --- .../docs/kit/20-core-concepts/10-routing.md | 45 ++++++++++++------- .../docs/kit/20-core-concepts/20-load.md | 35 ++++++++------- .../kit/20-core-concepts/30-form-actions.md | 25 +++++------ .../20-core-concepts/50-state-management.md | 18 ++++---- .../25-build-and-deploy/90-adapter-vercel.md | 4 +- .../kit/30-advanced/10-advanced-routing.md | 6 +-- .../content/docs/kit/30-advanced/20-hooks.md | 6 ++- .../docs/kit/30-advanced/65-snapshots.md | 2 +- .../kit/30-advanced/67-shallow-routing.md | 2 +- .../docs/kit/40-best-practices/03-auth.md | 23 ++++++++++ .../kit/40-best-practices/05-performance.md | 2 +- .../docs/kit/98-reference/10-@sveltejs-kit.md | 6 +-- .../content/docs/kit/98-reference/26-$lib.md | 16 ++++++- .../content/docs/kit/98-reference/54-types.md | 2 +- .../svelte/01-introduction/03-svelte-files.md | 2 + .../docs/svelte/02-runes/03-$derived.md | 2 + .../docs/svelte/02-runes/04-$effect.md | 2 +- .../docs/svelte/03-template-syntax/12-use.md | 2 +- .../docs/svelte/06-runtime/02-context.md | 4 +- .../svelte/06-runtime/03-lifecycle-hooks.md | 9 ++-- .../svelte/07-misc/07-v5-migration-guide.md | 18 ++++---- .../docs/svelte/98-reference/20-svelte.md | 8 ++-- .../svelte/98-reference/21-svelte-action.md | 2 +- 23 files changed, 152 insertions(+), 89 deletions(-) create mode 100644 apps/svelte.dev/content/docs/kit/40-best-practices/03-auth.md diff --git a/apps/svelte.dev/content/docs/kit/20-core-concepts/10-routing.md b/apps/svelte.dev/content/docs/kit/20-core-concepts/10-routing.md index 0c48a2b2c2..66d2af54bb 100644 --- a/apps/svelte.dev/content/docs/kit/20-core-concepts/10-routing.md +++ b/apps/svelte.dev/content/docs/kit/20-core-concepts/10-routing.md @@ -37,17 +37,22 @@ A `+page.svelte` component defines a page of your app. By default, pages are ren Home ``` +Pages can receive data from `load` functions via the `data` prop. + ```svelte

{data.title}

{@html data.content}
``` +> [!LEGACY] In Svelte 4 +> In Svelte 4, you'd use `export let data` instead + > [!NOTE] Note that SvelteKit uses `` elements to navigate between routes, rather than a framework-specific `` component. ### +page.js @@ -153,21 +158,29 @@ But in many apps, there are elements that should be visible on _every_ page, suc To create a layout that applies to every page, make a file called `src/routes/+layout.svelte`. The default layout (the one that SvelteKit uses if you don't bring your own) looks like this... -```html - +```svelte + + +{@render children()} ``` -...but we can add whatever markup, styles and behaviour we want. The only requirement is that the component includes a `` for the page content. For example, let's add a nav bar: +...but we can add whatever markup, styles and behaviour we want. The only requirement is that the component includes a `@render` tag for the page content. For example, let's add a nav bar: + +```svelte + + -```html -/// file: src/routes/+layout.svelte - +{@render children()} ``` If we create pages for `/`, `/about` and `/settings`... @@ -196,8 +209,8 @@ We can create a layout that only applies to pages below `/settings` (while inher ```svelte

Settings

@@ -208,7 +221,7 @@ We can create a layout that only applies to pages below `/settings` (while inher {/each} - +{@render children()} ``` You can see how `data` is populated by looking at the `+layout.js` example in the next section just below. @@ -239,8 +252,8 @@ Data returned from a layout's `load` function is also available to all its child ```svelte @@ -370,13 +383,13 @@ export async function fallback({ request }) { Throughout the examples above, we've been importing types from a `$types.d.ts` file. This is a file SvelteKit creates for you in a hidden directory if you're using TypeScript (or JavaScript with JSDoc type annotations) to give you type safety when working with your root files. -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`: +For example, annotating `let { data } = $props()` with `PageData` (or `LayoutData`, for a `+layout.svelte` file) tells TypeScript that the type of `data` is whatever was returned from `load`: ```svelte ``` diff --git a/apps/svelte.dev/content/docs/kit/20-core-concepts/20-load.md b/apps/svelte.dev/content/docs/kit/20-core-concepts/20-load.md index 3e50259a33..9de2b83ead 100644 --- a/apps/svelte.dev/content/docs/kit/20-core-concepts/20-load.md +++ b/apps/svelte.dev/content/docs/kit/20-core-concepts/20-load.md @@ -24,14 +24,17 @@ export function load({ params }) { ```svelte

{data.post.title}

{@html data.post.content}
``` +> [!LEGACY] In Svelte 4 +> In Svelte 4, you'd use `export let data` instead + Thanks to the generated `$types` module, we get full type safety. 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. @@ -85,13 +88,13 @@ export async function load() { ```svelte
- - + + {@render children()}