Skip to content

Commit ce20e1d

Browse files
sync svelte docs
1 parent d56c1ca commit ce20e1d

File tree

10 files changed

+301
-1
lines changed

10 files changed

+301
-1
lines changed

apps/svelte.dev/content/docs/svelte/02-runes/02-$state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ todos.push({
5151
});
5252
```
5353

54-
> [!NOTE] When you update properties of proxies, the original object is _not_ mutated.
54+
> [!NOTE] When you update properties of proxies, the original object is _not_ mutated. If you desire to use your own proxy handlers in a state proxy, [you should wrap the object _after_ wrapping it in `$state`](https://svelte.dev/playground/hello-world?version=latest#H4sIAAAAAAAACpWR3WoDIRCFX2UqhWyIJL3erAulL9C7XnQLMe5ksbUqOpsfln33YuyGFNJC8UKdc2bOhw7Myk9kJXsJ0nttO9jcR5KEG9AWJDwHdzwxznbaYGTl68Do5JM_FRifuh-9X8Y9Gkq1rYx4q66cJbQUWcmqqIL2VDe2IYMEbvuOikBADi-GJDSkXG-phId0G-frye2DO2psQYDFQ0Ys8gQO350dUkEydEg82T0GOs0nsSG9g2IqgxACZueo2ZUlpdvoDC6N64qsg1QKY8T2bpZp8gpIfbCQ85Zn50Ud82HkeY83uDjspenxv3jXcSDyjPWf9L1vJf0GH666J-jLu1ery4dV257IWXBWGa0-xFDMQdTTn2ScxWKsn86ROsLwQxqrVR5QM84Ij8TKFD2-cUZSm4O2LSt30kQcvwCgCmfZnAIAAA==).
5555
5656
Note that if you destructure a reactive value, the references are not reactive — as in normal JavaScript, they are evaluated at the point of destructuring:
5757

apps/svelte.dev/content/docs/svelte/98-reference/.generated/client-errors.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
<!-- This file is generated by scripts/process-messages/index.js. Do not edit! -->
22

3+
### async_derived_orphan
4+
5+
```
6+
Cannot create a `$derived(...)` with an `await` expression outside of an effect tree
7+
```
8+
9+
In Svelte there are two types of reaction — [`$derived`](/docs/svelte/$derived) and [`$effect`](/docs/svelte/$effect). Deriveds can be created anywhere, because they run _lazily_ and can be [garbage collected](https://developer.mozilla.org/en-US/docs/Glossary/Garbage_collection) if nothing references them. Effects, by contrast, keep running eagerly whenever their dependencies change, until they are destroyed.
10+
11+
Because of this, effects can only be created inside other effects (or [effect roots](/docs/svelte/$effect#$effect.root), such as the one that is created when you first mount a component) so that Svelte knows when to destroy them.
12+
13+
Some sleight of hand occurs when a derived contains an `await` expression: Since waiting until we read `{await getPromise()}` to call `getPromise` would be too late, we use an effect to instead call it proactively, notifying Svelte when the value is available. But since we're using an effect, we can only create asynchronous deriveds inside another effect.
14+
315
### bind_invalid_checkbox_value
416

517
```
@@ -68,12 +80,28 @@ Effect cannot be created inside a `$derived` value that was not itself created i
6880
`%rune%` can only be used inside an effect (e.g. during component initialisation)
6981
```
7082

83+
### effect_pending_outside_reaction
84+
85+
```
86+
`$effect.pending()` can only be called inside an effect or derived
87+
```
88+
7189
### effect_update_depth_exceeded
7290

7391
```
7492
Maximum update depth exceeded. This can happen when a reactive block or effect repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops
7593
```
7694

95+
### flush_sync_in_effect
96+
97+
```
98+
Cannot use `flushSync` inside an effect
99+
```
100+
101+
The `flushSync()` function can be used to flush any pending effects synchronously. It cannot be used if effects are currently being flushed — in other words, you can call it after a state change but _not_ inside an effect.
102+
103+
This restriction only applies when using the `experimental.async` option, which will be active by default in Svelte 6.
104+
77105
### get_abort_signal_outside_reaction
78106

79107
```
@@ -116,6 +144,14 @@ Rest element properties of `$props()` such as `%property%` are readonly
116144
The `%rune%` rune is only available inside `.svelte` and `.svelte.js/ts` files
117145
```
118146

147+
### set_context_after_init
148+
149+
```
150+
`setContext` must be called when a component first initializes, not in a subsequent effect or after an `await` expression
151+
```
152+
153+
This restriction only applies when using the `experimental.async` option, which will be active by default in Svelte 6.
154+
119155
### state_descriptors_fixed
120156

121157
```

apps/svelte.dev/content/docs/svelte/98-reference/.generated/client-warnings.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,67 @@ function add() {
3434
}
3535
```
3636
37+
### await_reactivity_loss
38+
39+
```
40+
Detected reactivity loss when reading `%name%`. This happens when state is read in an async function after an earlier `await`
41+
```
42+
43+
Svelte's signal-based reactivity works by tracking which bits of state are read when a template or `$derived(...)` expression executes. If an expression contains an `await`, Svelte transforms it such that any state _after_ the `await` is also tracked — in other words, in a case like this...
44+
45+
```js
46+
let total = $derived(await a + b);
47+
```
48+
49+
...both `a` and `b` are tracked, even though `b` is only read once `a` has resolved, after the initial execution.
50+
51+
This does _not_ apply to an `await` that is not 'visible' inside the expression. In a case like this...
52+
53+
```js
54+
async function sum() {
55+
return await a + b;
56+
}
57+
58+
let total = $derived(await sum());
59+
```
60+
61+
...`total` will depend on `a` (which is read immediately) but not `b` (which is not). The solution is to pass the values into the function:
62+
63+
```js
64+
async function sum(a, b) {
65+
return await a + b;
66+
}
67+
68+
let total = $derived(await sum(a, b));
69+
```
70+
71+
### await_waterfall
72+
73+
```
74+
An async derived, `%name%` (%location%) was not read immediately after it resolved. This often indicates an unnecessary waterfall, which can slow down your app
75+
```
76+
77+
In a case like this...
78+
79+
```js
80+
let a = $derived(await one());
81+
let b = $derived(await two());
82+
```
83+
84+
...the second `$derived` will not be created until the first one has resolved. Since `await two()` does not depend on the value of `a`, this delay, often described as a 'waterfall', is unnecessary.
85+
86+
(Note that if the values of `await one()` and `await two()` subsequently change, they can do so concurrently — the waterfall only occurs when the deriveds are first created.)
87+
88+
You can solve this by creating the promises first and _then_ awaiting them:
89+
90+
```js
91+
let aPromise = $derived(one());
92+
let bPromise = $derived(two());
93+
94+
let a = $derived(await aPromise);
95+
let b = $derived(await bPromise);
96+
```
97+
3798
### binding_property_non_reactive
3899
39100
```

apps/svelte.dev/content/docs/svelte/98-reference/.generated/compile-errors.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,12 @@ Expected token %token%
480480
Expected whitespace
481481
```
482482

483+
### experimental_async
484+
485+
```
486+
Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless the `experimental.async` compiler option is `true`
487+
```
488+
483489
### export_undefined
484490

485491
```
@@ -534,6 +540,12 @@ The arguments keyword cannot be used within the template or at the top level of
534540
%message%
535541
```
536542

543+
### legacy_await_invalid
544+
545+
```
546+
Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless in runes mode
547+
```
548+
537549
### legacy_export_invalid
538550

539551
```

apps/svelte.dev/content/docs/svelte/98-reference/.generated/shared-errors.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
<!-- This file is generated by scripts/process-messages/index.js. Do not edit! -->
22

3+
### await_outside_boundary
4+
5+
```
6+
Cannot await outside a `<svelte:boundary>` with a `pending` snippet
7+
```
8+
9+
The `await` keyword can only appear in a `$derived(...)` or template expression, or at the top level of a component's `<script>` block, if it is inside a [`<svelte:boundary>`](/docs/svelte/svelte-boundary) that has a `pending` snippet:
10+
11+
```svelte
12+
<svelte:boundary>
13+
<p>{await getData()}</p>
14+
15+
{#snippet pending()}
16+
<p>loading...</p>
17+
{/snippet}
18+
</svelte:boundary>
19+
```
20+
21+
This restriction may be lifted in a future version of Svelte.
22+
323
### invalid_default_snippet
424

525
```

apps/svelte.dev/content/docs/svelte/98-reference/20-svelte.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
onDestroy,
2525
onMount,
2626
setContext,
27+
settled,
2728
tick,
2829
unmount,
2930
untrack
@@ -496,6 +497,21 @@ function setContext<T>(key: any, context: T): T;
496497

497498

498499

500+
## settled
501+
502+
Returns a promise that resolves once any state changes, and asynchronous work resulting from them,
503+
have resolved and the DOM has been updated
504+
505+
<div class="ts-block">
506+
507+
```dts
508+
function settled(): Promise<void>;
509+
```
510+
511+
</div>
512+
513+
514+
499515
## tick
500516

501517
Returns a promise that resolves once any pending state changes have been applied.

apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-compiler.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,32 @@ warningFilter?: (warning: Warning) => boolean;
12611261
A function that gets a `Warning` as an argument and returns a boolean.
12621262
Use this to filter out warnings. Return `true` to keep the warning, `false` to discard it.
12631263

1264+
</div>
1265+
</div>
1266+
1267+
<div class="ts-block-property">
1268+
1269+
```dts
1270+
experimental?: {/*…*/}
1271+
```
1272+
1273+
<div class="ts-block-property-details">
1274+
1275+
Experimental options
1276+
1277+
<div class="ts-block-property-children"><div class="ts-block-property">
1278+
1279+
```dts
1280+
async?: boolean;
1281+
```
1282+
1283+
<div class="ts-block-property-details">
1284+
1285+
Allow `await` keyword in deriveds, template expressions, and the top level of components
1286+
1287+
</div>
1288+
</div></div>
1289+
12641290
</div>
12651291
</div></div>
12661292

apps/svelte.dev/content/docs/svelte/98-reference/30-compiler-errors.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,12 @@ Expected token %token%
485485
Expected whitespace
486486
```
487487

488+
### experimental_async
489+
490+
```
491+
Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless the `experimental.async` compiler option is `true`
492+
```
493+
488494
### export_undefined
489495

490496
```
@@ -539,6 +545,12 @@ The arguments keyword cannot be used within the template or at the top level of
539545
%message%
540546
```
541547

548+
### legacy_await_invalid
549+
550+
```
551+
Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless in runes mode
552+
```
553+
542554
### legacy_export_invalid
543555

544556
```

apps/svelte.dev/content/docs/svelte/98-reference/30-runtime-errors.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ title: 'Runtime errors'
77

88
<!-- This file is generated by scripts/process-messages/index.js. Do not edit! -->
99

10+
### async_derived_orphan
11+
12+
```
13+
Cannot create a `$derived(...)` with an `await` expression outside of an effect tree
14+
```
15+
16+
In Svelte there are two types of reaction — [`$derived`](/docs/svelte/$derived) and [`$effect`](/docs/svelte/$effect). Deriveds can be created anywhere, because they run _lazily_ and can be [garbage collected](https://developer.mozilla.org/en-US/docs/Glossary/Garbage_collection) if nothing references them. Effects, by contrast, keep running eagerly whenever their dependencies change, until they are destroyed.
17+
18+
Because of this, effects can only be created inside other effects (or [effect roots](/docs/svelte/$effect#$effect.root), such as the one that is created when you first mount a component) so that Svelte knows when to destroy them.
19+
20+
Some sleight of hand occurs when a derived contains an `await` expression: Since waiting until we read `{await getPromise()}` to call `getPromise` would be too late, we use an effect to instead call it proactively, notifying Svelte when the value is available. But since we're using an effect, we can only create asynchronous deriveds inside another effect.
21+
1022
### bind_invalid_checkbox_value
1123

1224
```
@@ -75,12 +87,28 @@ Effect cannot be created inside a `$derived` value that was not itself created i
7587
`%rune%` can only be used inside an effect (e.g. during component initialisation)
7688
```
7789

90+
### effect_pending_outside_reaction
91+
92+
```
93+
`$effect.pending()` can only be called inside an effect or derived
94+
```
95+
7896
### effect_update_depth_exceeded
7997

8098
```
8199
Maximum update depth exceeded. This can happen when a reactive block or effect repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops
82100
```
83101

102+
### flush_sync_in_effect
103+
104+
```
105+
Cannot use `flushSync` inside an effect
106+
```
107+
108+
The `flushSync()` function can be used to flush any pending effects synchronously. It cannot be used if effects are currently being flushed — in other words, you can call it after a state change but _not_ inside an effect.
109+
110+
This restriction only applies when using the `experimental.async` option, which will be active by default in Svelte 6.
111+
84112
### get_abort_signal_outside_reaction
85113

86114
```
@@ -123,6 +151,14 @@ Rest element properties of `$props()` such as `%property%` are readonly
123151
The `%rune%` rune is only available inside `.svelte` and `.svelte.js/ts` files
124152
```
125153

154+
### set_context_after_init
155+
156+
```
157+
`setContext` must be called when a component first initializes, not in a subsequent effect or after an `await` expression
158+
```
159+
160+
This restriction only applies when using the `experimental.async` option, which will be active by default in Svelte 6.
161+
126162
### state_descriptors_fixed
127163

128164
```
@@ -190,6 +226,26 @@ Certain methods such as `mount` cannot be invoked while running in a server cont
190226

191227
<!-- This file is generated by scripts/process-messages/index.js. Do not edit! -->
192228

229+
### await_outside_boundary
230+
231+
```
232+
Cannot await outside a `<svelte:boundary>` with a `pending` snippet
233+
```
234+
235+
The `await` keyword can only appear in a `$derived(...)` or template expression, or at the top level of a component's `<script>` block, if it is inside a [`<svelte:boundary>`](/docs/svelte/svelte-boundary) that has a `pending` snippet:
236+
237+
```svelte
238+
<svelte:boundary>
239+
<p>{await getData()}</p>
240+
241+
{#snippet pending()}
242+
<p>loading...</p>
243+
{/snippet}
244+
</svelte:boundary>
245+
```
246+
247+
This restriction may be lifted in a future version of Svelte.
248+
193249
### invalid_default_snippet
194250

195251
```

0 commit comments

Comments
 (0)