Skip to content

Commit 2e49783

Browse files
authored
docs: fix code snippets (#16367)
1 parent 96ff125 commit 2e49783

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

documentation/docs/98-reference/.generated/client-warnings.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ Detected reactivity loss when reading `%name%`. This happens when state is read
4343
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...
4444

4545
```js
46+
let a = Promise.resolve(1);
47+
let b = 2;
48+
// ---cut---
4649
let total = $derived(await a + b);
4750
```
4851

@@ -51,6 +54,9 @@ let total = $derived(await a + b);
5154
This does _not_ apply to an `await` that is not 'visible' inside the expression. In a case like this...
5255

5356
```js
57+
let a = Promise.resolve(1);
58+
let b = 2;
59+
// ---cut---
5460
async function sum() {
5561
return await a + b;
5662
}
@@ -61,6 +67,13 @@ let total = $derived(await sum());
6167
...`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:
6268
6369
```js
70+
let a = Promise.resolve(1);
71+
let b = 2;
72+
// ---cut---
73+
/**
74+
* @param {Promise<number>} a
75+
* @param {number} b
76+
*/
6477
async function sum(a, b) {
6578
return await a + b;
6679
}
@@ -77,6 +90,9 @@ An async derived, `%name%` (%location%) was not read immediately after it resolv
7790
In a case like this...
7891
7992
```js
93+
async function one() { return 1 }
94+
async function two() { return 2 }
95+
// ---cut---
8096
let a = $derived(await one());
8197
let b = $derived(await two());
8298
```
@@ -88,6 +104,9 @@ let b = $derived(await two());
88104
You can solve this by creating the promises first and _then_ awaiting them:
89105
90106
```js
107+
async function one() { return 1 }
108+
async function two() { return 2 }
109+
// ---cut---
91110
let aPromise = $derived(one());
92111
let bPromise = $derived(two());
93112

packages/svelte/messages/client-warnings/warnings.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ function add() {
3737
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...
3838
3939
```js
40+
let a = Promise.resolve(1);
41+
let b = 2;
42+
// ---cut---
4043
let total = $derived(await a + b);
4144
```
4245
@@ -45,6 +48,9 @@ let total = $derived(await a + b);
4548
This does _not_ apply to an `await` that is not 'visible' inside the expression. In a case like this...
4649
4750
```js
51+
let a = Promise.resolve(1);
52+
let b = 2;
53+
// ---cut---
4854
async function sum() {
4955
return await a + b;
5056
}
@@ -55,6 +61,13 @@ let total = $derived(await sum());
5561
...`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:
5662
5763
```js
64+
let a = Promise.resolve(1);
65+
let b = 2;
66+
// ---cut---
67+
/**
68+
* @param {Promise<number>} a
69+
* @param {number} b
70+
*/
5871
async function sum(a, b) {
5972
return await a + b;
6073
}
@@ -69,6 +82,9 @@ let total = $derived(await sum(a, b));
6982
In a case like this...
7083
7184
```js
85+
async function one() { return 1 }
86+
async function two() { return 2 }
87+
// ---cut---
7288
let a = $derived(await one());
7389
let b = $derived(await two());
7490
```
@@ -80,6 +96,9 @@ let b = $derived(await two());
8096
You can solve this by creating the promises first and _then_ awaiting them:
8197
8298
```js
99+
async function one() { return 1 }
100+
async function two() { return 2 }
101+
// ---cut---
83102
let aPromise = $derived(one());
84103
let bPromise = $derived(two());
85104

0 commit comments

Comments
 (0)