From db7652116ec1c9c1962861781c6ca978baffef5c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 25 Jul 2024 12:01:46 -0400 Subject: [PATCH] chore: tweak `$state.is` warning docs a bit more (#12605) --- .../messages/client-warnings/warnings.md | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/svelte/messages/client-warnings/warnings.md b/packages/svelte/messages/client-warnings/warnings.md index 695776dd60..cae88b0bef 100644 --- a/packages/svelte/messages/client-warnings/warnings.md +++ b/packages/svelte/messages/client-warnings/warnings.md @@ -42,22 +42,26 @@ > Reactive `$state(...)` proxies and the values they proxy have different identities. Because of this, comparisons with `%operator%` will produce unexpected results. Consider using `$state.is(a, b)` instead%details% -`$state(...)` does create a proxy of the value it is passed. Therefore, the resulting object has a different identity and equality checks will always return `false`: +`$state(...)` creates a [proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) of the value it is passed. The proxy and the value have different identities, meaning equality checks will always return `false`: ```svelte ``` -Most of the time this will not be a problem in practise because it is very rare to keep the original value around to later compare it against a state value. In case it happens, Svelte will warn you about it in development mode and suggest to use `$state.is` instead, which is able to unwrap the proxy and compare the original values: +In the rare case that you need to compare them, you can use `$state.is`, which unwraps proxies: ```svelte ``` + +During development, Svelte will warn you when comparing values with proxies.