-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supported Method for Detecting Proxies #15345
Comments
I don't think this is really that necessary; if you're concerned about whether an object is a |
Interesting thing: The Svelte framework will always refer to the value the proxy is for instead of the proxy itself: <script>
let name = $state('John')
</script>
<pre>Is Proxy? {name instanceof Proxy}</pre>
<pre>Is string? {typeof name === 'string'}</pre> And: <script>
let name = $state('John')
const isProxy = $derived(name instanceof Proxy)
const isString = $derived(typeof name === 'string')
</script>
<pre>Is Proxy? {isProxy}</pre>
<pre>Is string? {isString}</pre> Tells you that |
If some code cannot accept proxies, as said @Ocean-OS, just do |
That seems like a bit of a misunderstanding. Svelte will not create proxies for primitive values (strings, numbers, booleans) at all. You need to set the state to a plain object or array for a proxy to be created. This proxy then can be passed around. |
Yeah, the |
Describe the problem
A common concern with svelte 5's introduction of rune proxies is the inability to detect proxies i.e issue-13562. A common issue when migrating code is sudden errors erupting from libraries/apis that don't accept proxies. Adding to that issue, there is no supported way to method to detect if an object is a reactive proxy, so user's have to use try/catch or other homegrown methods to detect if an object is a proxy.
Describe the proposed solution
Can we have a supported method for detecting proxies
Ideally, the proxy check is something integrated in Svelte's current proxy logic (linked above). Alternatively, a more generic javascript proxy detection method could work.
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: