Skip to content

Commit 0796a76

Browse files
committed
Merge branch 'main' into declaration-maps
2 parents 3e1548b + 891429e commit 0796a76

File tree

137 files changed

+1772
-912
lines changed

Some content is hidden

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

137 files changed

+1772
-912
lines changed

.changeset/khaki-melons-add.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/many-gorillas-shout.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/package': patch
3+
---
4+
5+
fix: resolve aliases more robustly

.changeset/slimy-cows-listen.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
node-version: 22
3030
cache: pnpm
3131
- run: pnpm install --frozen-lockfile
32+
- run: pnpm build
3233
- run: pnpx pkg-pr-new publish --comment=off ./packages/*
3334
lint-all:
3435
runs-on: ubuntu-latest

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Pages can receive data from `load` functions via the `data` prop.
4242
```svelte
4343
<!--- file: src/routes/blog/[slug]/+page.svelte --->
4444
<script>
45-
/** @type {{ data: import('./$types').PageData }} */
45+
/** @type {import('./$types').PageProps} */
4646
let { data } = $props();
4747
</script>
4848
@@ -51,7 +51,9 @@ Pages can receive data from `load` functions via the `data` prop.
5151
```
5252

5353
> [!LEGACY]
54-
> In Svelte 4, you'd use `export let data` instead
54+
> `PageProps` was added in 2.16.0. In earlier versions, you had to type the `data` property manually with `PageData` instead, see [$types](#\$types).
55+
>
56+
> In Svelte 4, you'd use `export let data` instead.
5557
5658
> [!NOTE] SvelteKit uses `<a>` elements to navigate between routes, rather than a framework-specific `<Link>` component.
5759
@@ -212,7 +214,7 @@ We can create a layout that only applies to pages below `/settings` (while inher
212214
```svelte
213215
<!--- file: src/routes/settings/+layout.svelte --->
214216
<script>
215-
/** @type {{ data: import('./$types').LayoutData, children: import('svelte').Snippet }} */
217+
/** @type {import('./$types').LayoutProps} */
216218
let { data, children } = $props();
217219
</script>
218220
@@ -227,6 +229,9 @@ We can create a layout that only applies to pages below `/settings` (while inher
227229
{@render children()}
228230
```
229231

232+
> [!LEGACY]
233+
> `LayoutProps` was added in 2.16.0. In earlier versions, you had to [type the properties manually instead](#\$types).
234+
230235
You can see how `data` is populated by looking at the `+layout.js` example in the next section just below.
231236

232237
By default, each layout inherits the layout above it. Sometimes that isn't what you want - in this case, [advanced layouts](advanced-routing#Advanced-layouts) can help you.
@@ -255,7 +260,7 @@ Data returned from a layout's `load` function is also available to all its child
255260
```svelte
256261
<!--- file: src/routes/settings/profile/+page.svelte --->
257262
<script>
258-
/** @type {{ data: import('./$types').PageData }} */
263+
/** @type {import('./$types').PageProps} */
259264
let { data } = $props();
260265
261266
console.log(data.sections); // [{ slug: 'profile', title: 'Profile' }, ...]
@@ -388,16 +393,33 @@ export async function fallback({ request }) {
388393
389394
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.
390395
391-
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`:
396+
For example, annotating `let { data } = $props()` with `PageProps` (or `LayoutProps`, for a `+layout.svelte` file) tells TypeScript that the type of `data` is whatever was returned from `load`:
392397
393398
```svelte
394399
<!--- file: src/routes/blog/[slug]/+page.svelte --->
395400
<script>
396-
/** @type {{ data: import('./$types').PageData }} */
401+
/** @type {import('./$types').PageProps} */
397402
let { data } = $props();
398403
</script>
399404
```
400405
406+
> [!NOTE]
407+
> The `PageProps` and `LayoutProps` types, added in 2.16.0, are a shortcut for typing the `data` prop as `PageData` or `LayoutData`, as well as other props, such as `form` for pages, or `children` for layouts. In earlier versions, you had to type these properties manually. For example, for a page:
408+
>
409+
> ```js
410+
> /// file: +page.svelte
411+
> /** @type {{ data: import('./$types').PageData, form: import('./$types').ActionData }} */
412+
> let { data, form } = $props();
413+
> ```
414+
>
415+
> Or, for a layout:
416+
>
417+
> ```js
418+
> /// file: +layout.svelte
419+
> /** @type {{ data: import('./$types').LayoutData, children: Snippet }} */
420+
> let { data, children } = $props();
421+
> ```
422+
401423
In turn, annotating the `load` function with `PageLoad`, `PageServerLoad`, `LayoutLoad` or `LayoutServerLoad` (for `+page.js`, `+page.server.js`, `+layout.js` and `+layout.server.js` respectively) ensures that `params` and the return value are correctly typed.
402424
403425
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`.

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function load({ params }) {
2424
```svelte
2525
<!--- file: src/routes/blog/[slug]/+page.svelte --->
2626
<script>
27-
/** @type {{ data: import('./$types').PageData }} */
27+
/** @type {import('./$types').PageProps} */
2828
let { data } = $props();
2929
</script>
3030
@@ -33,7 +33,14 @@ export function load({ params }) {
3333
```
3434

3535
> [!LEGACY]
36-
> In Svelte 4, you'd use `export let data` instead
36+
> Before version 2.16.0, the props of a page and layout had to be typed individually:
37+
> ```js
38+
> /// file: +page.svelte
39+
> /** @type {{ data: import('./$types').PageData }} */
40+
> let { data } = $props();
41+
> ```
42+
>
43+
> In Svelte 4, you'd use `export let data` instead.
3744
3845
Thanks to the generated `$types` module, we get full type safety.
3946
@@ -88,7 +95,7 @@ export async function load() {
8895
```svelte
8996
<!--- file: src/routes/blog/[slug]/+layout.svelte --->
9097
<script>
91-
/** @type {{ data: import('./$types').LayoutData, children: Snippet }} */
98+
/** @type {import('./$types').LayoutProps} */
9299
let { data, children } = $props();
93100
</script>
94101
@@ -111,14 +118,22 @@ export async function load() {
111118
</aside>
112119
```
113120

121+
> [!LEGACY]
122+
> `LayoutProps` was added in 2.16.0. In earlier versions, properties had to be typed individually:
123+
> ```js
124+
> /// file: +layout.svelte
125+
> /** @type {{ data: import('./$types').LayoutData, children: Snippet }} */
126+
> let { data, children } = $props();
127+
> ```
128+
114129
Data returned from layout `load` functions is available to child `+layout.svelte` components and the `+page.svelte` component as well as the layout that it 'belongs' to.
115130
116131
```svelte
117132
/// file: src/routes/blog/[slug]/+page.svelte
118133
<script>
119134
+++import { page } from '$app/state';+++
120135
121-
/** @type {{ data: import('./$types').PageData }} */
136+
/** @type {import('./$types').PageProps} */
122137
let { data } = $props();
123138
124139
+++ // we can access `data.posts` because it's returned from
@@ -372,7 +387,7 @@ export async function load({ parent }) {
372387
```svelte
373388
<!--- file: src/routes/abc/+page.svelte --->
374389
<script>
375-
/** @type {{ data: import('./$types').PageData }} */
390+
/** @type {import('./$types').PageProps} */
376391
let { data } = $props();
377392
</script>
378393
@@ -511,7 +526,7 @@ This is useful for creating skeleton loading states, for example:
511526
```svelte
512527
<!--- file: src/routes/blog/[slug]/+page.svelte --->
513528
<script>
514-
/** @type {{ data: import('./$types').PageData }} */
529+
/** @type {import('./$types').PageProps} */
515530
let { data } = $props();
516531
</script>
517532
@@ -652,7 +667,7 @@ export async function load({ fetch, depends }) {
652667
<script>
653668
import { invalidate, invalidateAll } from '$app/navigation';
654669
655-
/** @type {{ data: import('./$types').PageData }} */
670+
/** @type {import('./$types').PageProps} */
656671
let { data } = $props();
657672
658673
function rerunLoadFunction() {

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export const actions = {
140140
```svelte
141141
<!--- file: src/routes/login/+page.svelte --->
142142
<script>
143-
/** @type {{ data: import('./$types').PageData, form: import('./$types').ActionData }} */
143+
/** @type {import('./$types').PageProps} */
144144
let { data, form } = $props();
145145
</script>
146146

@@ -152,7 +152,14 @@ export const actions = {
152152
```
153153
154154
> [!LEGACY]
155-
> In Svelte 4, you'd use `export let data` and `export let form` instead to declare properties
155+
> `PageProps` was added in 2.16.0. In earlier versions, you had to type the `data` and `form` properties individually:
156+
> ```js
157+
> /// file: +page.svelte
158+
> /** @type {{ data: import('./$types').PageData, form: import('./$types').ActionData }} */
159+
> let { data, form } = $props();
160+
> ```
161+
>
162+
> In Svelte 4, you'd use `export let data` and `export let form` instead to declare properties.
156163
157164
### Validation errors
158165
@@ -339,7 +346,7 @@ The easiest way to progressively enhance a form is to add the `use:enhance` acti
339346
<script>
340347
+++import { enhance } from '$app/forms';+++
341348

342-
/** @type {{ form: import('./$types').ActionData }} */
349+
/** @type {import('./$types').PageProps} */
343350
let { form } = $props();
344351
</script>
345352

@@ -390,7 +397,7 @@ If you return a callback, you may need to reproduce part of the default `use:enh
390397
<script>
391398
import { enhance, +++applyAction+++ } from '$app/forms';
392399

393-
/** @type {{ form: import('./$types').ActionData }} */
400+
/** @type {import('./$types').PageProps} */
394401
let { form } = $props();
395402
</script>
396403

@@ -427,7 +434,7 @@ We can also implement progressive enhancement ourselves, without `use:enhance`,
427434
import { invalidateAll, goto } from '$app/navigation';
428435
import { applyAction, deserialize } from '$app/forms';
429436

430-
/** @type {{ form: import('./$types').ActionData }} */
437+
/** @type {import('./$types').PageProps} */
431438
let { form } = $props();
432439

433440
/** @param {SubmitEvent & { currentTarget: EventTarget & HTMLFormElement}} event */

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ You might wonder how we're able to use `page.data` and other [app state]($app-st
8989
<script>
9090
import { setContext } from 'svelte';
9191
92-
/** @type {{ data: import('./$types').LayoutData }} */
92+
/** @type {import('./$types').LayoutProps} */
9393
let { data } = $props();
9494
9595
// Pass a function referencing our state
@@ -126,7 +126,7 @@ When you navigate around your application, SvelteKit reuses existing layout and
126126
```svelte
127127
<!--- file: src/routes/blog/[slug]/+page.svelte --->
128128
<script>
129-
/** @type {{ data: import('./$types').PageData }} */
129+
/** @type {import('./$types').PageProps} */
130130
let { data } = $props();
131131
132132
// THIS CODE IS BUGGY!
@@ -149,7 +149,7 @@ Instead, we need to make the value [_reactive_](/tutorial/svelte/state):
149149
```svelte
150150
/// file: src/routes/blog/[slug]/+page.svelte
151151
<script>
152-
/** @type {{ data: import('./$types').PageData }} */
152+
/** @type {import('./$types').PageProps} */
153153
let { data } = $props();
154154
155155
+++ let wordCount = $derived(data.content.split(' ').length);

documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ export async function POST({ request, platform }) {
8282

8383
> [!NOTE] SvelteKit's built-in `$env` module should be preferred for environment variables.
8484
85-
To include type declarations for your bindings, reference them in your `src/app.d.ts`:
85+
To make these types available to your app, install `@cloudflare/workers-types` and reference them in your `src/app.d.ts`:
8686

8787
```ts
8888
/// file: src/app.d.ts
89-
import { KVNamespace, DurableObjectNamespace } from '@cloudflare/workers-types';
89+
+++import { KVNamespace, DurableObjectNamespace } from '@cloudflare/workers-types';+++
9090

9191
declare global {
9292
namespace App {
@@ -120,7 +120,7 @@ However, they will have no effect on responses dynamically rendered by SvelteKit
120120

121121
### Further reading
122122

123-
You may wish to refer to [Cloudflare's documentation for deploying a SvelteKit site](https://developers.cloudflare.com/pages/framework-guides/deploy-a-svelte-site).
123+
You may wish to refer to [Cloudflare's documentation for deploying a SvelteKit site](https://developers.cloudflare.com/pages/framework-guides/deploy-a-svelte-kit-site).
124124

125125
### Accessing the file system
126126

documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ export async function POST({ request, platform }) {
103103

104104
> [!NOTE] SvelteKit's built-in `$env` module should be preferred for environment variables.
105105
106-
To include type declarations for your bindings, reference them in your `src/app.d.ts`:
106+
To make these types available to your app, install `@cloudflare/workers-types` and reference them in your `src/app.d.ts`:
107107

108108
```ts
109109
/// file: src/app.d.ts
110-
import { KVNamespace, DurableObjectNamespace } from '@cloudflare/workers-types';
110+
+++import { KVNamespace, DurableObjectNamespace } from '@cloudflare/workers-types';+++
111111

112112
declare global {
113113
namespace App {

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

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ export default {
9191

9292
Vercel supports [Incremental Static Regeneration](https://vercel.com/docs/incremental-static-regeneration) (ISR), which provides the performance and cost advantages of prerendered content with the flexibility of dynamically rendered content.
9393

94+
> Use ISR only on routes where every visitor should see the same content (much like when you prerender). If there's anything user-specific happening (like session cookies), they should happen on the client via JavaScript only to not leak sensitive information across visits
95+
9496
To add ISR to a route, include the `isr` property in your `config` object:
9597

9698
```js
@@ -99,24 +101,44 @@ import { BYPASS_TOKEN } from '$env/static/private';
99101

100102
export const config = {
101103
isr: {
102-
// Expiration time (in seconds) before the cached asset will be re-generated by invoking the Serverless Function.
103-
// Setting the value to `false` means it will never expire.
104104
expiration: 60,
105-
106-
// Random token that can be provided in the URL to bypass the cached version of the asset, by requesting the asset
107-
// with a __prerender_bypass=<token> cookie.
108-
//
109-
// Making a `GET` or `HEAD` request with `x-prerender-revalidate: <token>` will force the asset to be re-validated.
110105
bypassToken: BYPASS_TOKEN,
111-
112-
// List of valid query parameters. Other parameters (such as utm tracking codes) will be ignored,
113-
// ensuring that they do not result in content being regenerated unnecessarily
114106
allowQuery: ['search']
115107
}
116108
};
117109
```
118110

119-
The `expiration` property is required; all others are optional.
111+
> Using ISR on a route with `export const prerender = true` will have no effect, since the route is prerendered at build time
112+
113+
The `expiration` property is required; all others are optional. The properties are discussed in more detail below.
114+
115+
### expiration
116+
117+
The expiration time (in seconds) before the cached asset will be re-generated by invoking the Serverless Function. Setting the value to `false` means it will never expire. In that case, you likely want to define a bypass token to re-generate on demand.
118+
119+
### bypassToken
120+
121+
A random token that can be provided in the URL to bypass the cached version of the asset, by requesting the asset with a `__prerender_bypass=<token>` cookie.
122+
123+
Making a `GET` or `HEAD` request with `x-prerender-revalidate: <token>` will force the asset to be re-validated.
124+
125+
Note that the `BYPASS_TOKEN` string must be at least 32 characters long. You could generate one using the JavaScript console like so:
126+
127+
```console
128+
btoa(Math.random().toString()).substring(0,32);
129+
```
130+
131+
Set this string as an environment variable on Vercel by logging in and going to your project then Settings > Environment Variables. For "Key" put `BYPASS_TOKEN` and for "value" use the string generated above, then hit "Save".
132+
133+
To get this key known about for local development, you can use the [Vercel CLI](https://vercel.com/docs/cli/env) by running the `vercel env pull` command locally like so:
134+
135+
```console
136+
$ vercel env pull .env.development.local
137+
```
138+
139+
### allowQuery
140+
141+
A list of valid query parameters that contribute to the cache key. Other parameters (such as utm tracking codes) will be ignored, ensuring that they do not result in content being re-generated unnecessarily. By default, query parameters are ignored.
120142

121143
> Pages that are [prerendered](page-options#prerender) will ignore ISR configuration.
122144
@@ -140,7 +162,7 @@ export function load() {
140162
```svelte
141163
<!--- file: +layout.svelte --->
142164
<script>
143-
/** @type {{ data: import('./$types').LayoutServerData }} */
165+
/** @type {import('./$types').LayoutProps} */
144166
let { data } = $props();
145167
</script>
146168

0 commit comments

Comments
 (0)