## 客户警告 ### assignment\_value\_stale ``` Assignment to `%property%` property (%location%) will evaluate to the right-hand side, not the value of `%property%` following the assignment. This may result in unexpected behaviour. ``` 给定一个这样的案例... ```svelte

items: {JSON.stringify(object.items)}

``` ...當按鈕第一次被點擊時,推送到的數組是作業右側的 `[]`,但 `object.array` 的結果是一個空狀態代理。因此,推送的值將被丟棄。 您可以通过将其分为两个语句来修复此问题: ```js let object = { array: [0] }; // ---cut--- function add() { object.array ??= []; object.array.push(object.array.length); } ``` ### await\_reactivity\_loss ``` Detected reactivity loss when reading `%name%`. This happens when state is read in an async function after an earlier `await` ``` Svelte 的基于信号的响应性是通过跟踪模板或`$derived(...)`表达式执行时读取哪些状态位来工作的。如果一个表达式包含一个`await`,Svelte 会将其转换,以便跟踪`await`之后的任何状态*之后*——换句话说,在这种情况下…… ```js let a = Promise.resolve(1); let b = 2; // ---cut--- let total = $derived(await a + b); ``` ...两个`a`和`b`都被跟踪,即使`b`只在`a`解决后读取一次,在初始执行之后。 这并不适用于表达式内部不可见的 *await*。在这种情况下... ```js let a = Promise.resolve(1); let b = 2; // ---cut--- async function sum() { return await a + b; } let total = $derived(await sum()); ``` ...`total` 将取决于 `a`(立即读取)但不取决于 `b`(不读取)。解决方案是将值传递给函数: ```js let a = Promise.resolve(1); let b = 2; // ---cut--- /** * @param {Promise} a * @param {number} b */ async function sum(a, b) { return await a + b; } let total = $derived(await sum(a, b)); ``` ### await\_waterfall ``` An async derived, `%name%` (%location%) was not read immediately after it resolved. This often indicates an unnecessary waterfall, which can slow down your app ``` 在这种情况下... ```js async function one() { return 1 } async function two() { return 2 } // ---cut--- let a = $derived(await one()); let b = $derived(await two()); ``` ...第二个`$derived`将在第一个解决后创建。由于`await two()`不依赖于`a`的值,这种延迟,通常描述为“瀑布”,是不必要的。 (请注意,如果 `await one()` 和 `await two()` 的值随后更改,它们可以同时更改——瀑布效应仅在派生值首次创建时发生。) 您可以通过先创建承诺并在 *之后* 等待它们来解决此问题: ```js async function one() { return 1 } async function two() { return 2 } // ---cut--- let aPromise = $derived(one()); let bPromise = $derived(two()); let a = $derived(await aPromise); let b = $derived(await bPromise); ``` ### 绑定属性非响应式 ``` `%binding%` is binding to a non-reactive property ``` ``` `%binding%` (%location%) is binding to a non-reactive property ``` ### 控制台日志状态 ``` Your `console.%method%` contained `$state` proxies. Consider using `$inspect(...)` or `$state.snapshot(...)` instead ``` 当记录一个 [代理](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) 时,浏览器开发者工具将记录代理本身而不是它所代表的值。在 Svelte 的情况下,`$state` 代理的 'target' 可能与其当前值不相似,这可能会造成困惑。 最简单的方法记录值随时间变化的情况是使用 [`$inspect`](/docs/svelte/$inspect) 符文。或者,为了一次性记录某些内容(例如,在事件处理器内部),可以使用 [`$state.snapshot`](/docs/svelte/$state#$state.snapshot) 来获取当前值的快照。 ### 事件处理程序无效 ``` %handler% should be a function. Did you mean to %suggestion%? ``` ### 水合属性已更改 ``` The `%attribute%` attribute on `%html%` changed its value between server and client renders. The client value, `%value%`, will be ignored in favour of the server value ``` 某些属性,如`src`在``元素上,在激活过程中不会被修复,即服务器值将被保留。这是因为更新这些属性可能会导致图像被重新获取(或者在`