Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0b9fdfe

Browse files
Syncsvelte docs (#1415)
sync svelte docsCo-authored-by: svelte-docs-bot[bot] <196124396+svelte-docs-bot[bot]@users.noreply.github.com>
1 parentd56c1ca commit0b9fdfe

File tree

10 files changed

+357
-1
lines changed

10 files changed

+357
-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 need 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: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,86 @@ function add() {
3434
}
3535
```
3636
37+
### await_reactivity_loss
38+
39+
```
40+
Detected reactivity loss when reading`%name%`.This happens when state is readin anasyncfunction 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 a = Promise.resolve(1);
47+
let b = 2;
48+
// ---cut---
49+
let total = $derived(await a + b);
50+
```
51+
52+
...both `a` and `b` are tracked, even though `b` is only read once `a` has resolved, after the initial execution.
53+
54+
This does _not_ apply to an `await` that is not 'visible' inside the expression. In a case like this...
55+
56+
```js
57+
let a = Promise.resolve(1);
58+
let b = 2;
59+
// ---cut---
60+
async function sum() {
61+
returnawait a+ b;
62+
}
63+
64+
let total=$derived(awaitsum());
65+
```
66+
67+
...`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:
68+
69+
```js
70+
let a=Promise.resolve(1);
71+
let b=2;
72+
// ---cut---
73+
/**
74+
*@param{Promise<number>}a
75+
*@param{number}b
76+
*/
77+
asyncfunctionsum(a,b) {
78+
returnawait a+ b;
79+
}
80+
81+
let total=$derived(awaitsum(a, b));
82+
```
83+
84+
### await_waterfall
85+
86+
```
87+
Anasync derived,`%name%` (%location%) was not read immediately after itresolved.This often indicates an unnecessary waterfall, which can slow down your app
88+
```
89+
90+
In a case like this...
91+
92+
```js
93+
asyncfunctionone() {return1 }
94+
asyncfunctiontwo() {return2 }
95+
// ---cut---
96+
let a=$derived(awaitone());
97+
let b=$derived(awaittwo());
98+
```
99+
100+
...the second`$derived` will not be created until the first one has resolved. Since`awaittwo()` does not depend on the value of`a`, this delay, often described as a 'waterfall', is unnecessary.
101+
102+
(Note that if the values of`awaitone()` and`awaittwo()` subsequently change, they can do so concurrently — the waterfall only occurs when the deriveds are first created.)
103+
104+
You can solve this by creating the promises first and _then_ awaiting them:
105+
106+
```js
107+
asyncfunctionone() {return1 }
108+
asyncfunctiontwo() {return2 }
109+
// ---cut---
110+
let aPromise=$derived(one());
111+
let bPromise=$derived(two());
112+
113+
let a=$derived(await aPromise);
114+
let b=$derived(await bPromise);
115+
```
116+
37117
### binding_property_non_reactive
38118
39119
```

‎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: 22 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,27 @@ function setContext<T>(key: any, context: T): T;
496497

497498

498499

500+
##settled
501+
502+
<blockquoteclass="since note">
503+
504+
Available since 5.36
505+
506+
</blockquote>
507+
508+
Returns a promise that resolves once any state changes, and asynchronous work resulting from them,
509+
have resolved and the DOM has been updated
510+
511+
<divclass="ts-block">
512+
513+
```dts
514+
function settled(): Promise<void>;
515+
```
516+
517+
</div>
518+
519+
520+
499521
##tick
500522

501523
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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,44 @@ 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+
<divclass="ts-block-property">
1268+
1269+
```dts
1270+
experimental?: {/*…*/}
1271+
```
1272+
1273+
<divclass="ts-block-property-details">
1274+
1275+
<divclass="ts-block-property-bullets">
1276+
1277+
- <spanclass="tag since">available since</span> v5.36
1278+
1279+
</div>
1280+
1281+
Experimental options
1282+
1283+
<divclass="ts-block-property-children"><divclass="ts-block-property">
1284+
1285+
```dts
1286+
async?: boolean;
1287+
```
1288+
1289+
<divclass="ts-block-property-details">
1290+
1291+
<divclass="ts-block-property-bullets">
1292+
1293+
- <spanclass="tag since">available since</span> v5.36
1294+
1295+
</div>
1296+
1297+
Allow`await` keyword in deriveds, template expressions, and the top level of components
1298+
1299+
</div>
1300+
</div></div>
1301+
12641302
</div>
12651303
</div></div>
12661304

‎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
```

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp