-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed
Labels
Description
Describe the bug
Setting properties via this in a $state object does not trigger updates since the proxy gets bypassed. this is the raw object.
Should the setter function be called with the proxy as this?
(That is already the case for getters, but maybe there are some reasons not to do this, e.g. performance.)
Relevant code:
svelte/packages/svelte/src/internal/client/proxy.js
Lines 246 to 248 in 919e7ad
| // Set the new value before updating any signals so that any listeners get the new value | |
| // @ts-ignore | |
| target[prop] = value; |
If the descriptor is checked for a set function, that could be invoked with the receiver. Something along the lines of:
var descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
if (descriptor.set)
descriptor.set.call(receiver, value);
else
target[prop] = value;Reproduction
<script>
let text = $state({
value: 'svelte',
get uppercase() {
return this.value.toUpperCase()
},
set uppercase(v) {
this.value = v.toLowerCase()
}
})
</script>
<input bind:value={text.uppercase} />
<p>{text.value}</p>Logs
No response
System Info
REPLSeverity
annoyance