Skip to content

Commit f5103c6

Browse files
authored
docs: document derived use of $app/state's page (#13346)
#13305
1 parent 18d69fb commit f5103c6

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/kit/src/runtime/app/state/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ import { BROWSER } from 'esm-env';
3232
* {/if}
3333
* ```
3434
*
35+
* Changes to `page` are available exclusively with runes. (The legacy reactivity syntax will not reflect any changes)
36+
*
37+
* ```svelte
38+
* <!--- file: +page.svelte --->
39+
* <script>
40+
* import { page } from '$app/state';
41+
* const id = $derived(page.params.id); // This will correctly update id for usage on this page
42+
* $: badId = page.params.id; // Do not use; will never update after initial load
43+
* </script>
44+
* ```
45+
*
3546
* On the server, values can only be read during rendering (in other words _not_ in e.g. `load` functions). In the browser, the values can be read at any time.
3647
*
3748
* @type {import('@sveltejs/kit').Page}

packages/kit/types/index.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,6 +2356,17 @@ declare module '$app/state' {
23562356
* {/if}
23572357
* ```
23582358
*
2359+
* Changes to `page` are available exclusively with runes. (The legacy reactivity syntax will not reflect any changes)
2360+
*
2361+
* ```svelte
2362+
* <!--- file: +page.svelte --->
2363+
* <script>
2364+
* import { page } from '$app/state';
2365+
* const id = $derived(page.params.id); // This will correctly update id for usage on this page
2366+
* $: badId = page.params.id; // Do not use; will never update after initial load
2367+
* </script>
2368+
* ```
2369+
*
23592370
* On the server, values can only be read during rendering (in other words _not_ in e.g. `load` functions). In the browser, the values can be read at any time.
23602371
*
23612372
* */

0 commit comments

Comments
 (0)