fix: ignore mutation validation for props that are not proxies in more cases (#15759)

This fixes an off-by-one error - we did not bail if the top level of the prop wasn't a state already. Fixes #15727
pull/15756/head
Simon H 5 months ago committed by GitHub
parent bdf033e30f
commit 26e574f27f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ignore mutation validation for props that are not proxies in more cases

@ -31,13 +31,14 @@ export function create_ownership_validator(props) {
return result;
}
let value = props[name];
/** @type {any} */
let value = props;
for (let i = 1; i < path.length - 1; i++) {
for (let i = 0; i < path.length - 1; i++) {
value = value[path[i]];
if (!value?.[STATE_SYMBOL]) {
return result;
}
value = value[path[i]];
}
const location = sanitize_location(`${component[FILENAME]}:${line}:${column}`);

@ -0,0 +1,18 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
compileOptions: {
dev: true
},
test({ assert, target, warnings }) {
const btn = target.querySelector('button');
btn?.click();
flushSync();
assert.deepEqual(warnings, []);
},
warnings: []
});

@ -0,0 +1,8 @@
<script>
let { klass, getter_setter } = $props();
</script>
<button onclick={() => {
klass.y = 2;
getter_setter.y = 2;
}}>mutate</button>

@ -0,0 +1,21 @@
<script>
import Child from './child.svelte';
class X {
y = $state(1);
}
const klass = new X();
let y = $state(1);
const getter_setter = {
get y() {
return y;
},
set y(value) {
y = value;
}
}
</script>
<Child {klass} {getter_setter} />
Loading…
Cancel
Save