Skip to content

Commit 26e574f

Browse files
authored
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
1 parent bdf033e commit 26e574f

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

.changeset/modern-ducks-reflect.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ignore mutation validation for props that are not proxies in more cases

packages/svelte/src/internal/client/dev/ownership.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ export function create_ownership_validator(props) {
3131
return result;
3232
}
3333

34-
let value = props[name];
34+
/** @type {any} */
35+
let value = props;
3536

36-
for (let i = 1; i < path.length - 1; i++) {
37+
for (let i = 0; i < path.length - 1; i++) {
38+
value = value[path[i]];
3739
if (!value?.[STATE_SYMBOL]) {
3840
return result;
3941
}
40-
value = value[path[i]];
4142
}
4243

4344
const location = sanitize_location(`${component[FILENAME]}:${line}:${column}`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
compileOptions: {
6+
dev: true
7+
},
8+
9+
test({ assert, target, warnings }) {
10+
const btn = target.querySelector('button');
11+
btn?.click();
12+
flushSync();
13+
14+
assert.deepEqual(warnings, []);
15+
},
16+
17+
warnings: []
18+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
let { klass, getter_setter } = $props();
3+
</script>
4+
5+
<button onclick={() => {
6+
klass.y = 2;
7+
getter_setter.y = 2;
8+
}}>mutate</button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script>
2+
import Child from './child.svelte';
3+
4+
class X {
5+
y = $state(1);
6+
}
7+
8+
const klass = new X();
9+
10+
let y = $state(1);
11+
const getter_setter = {
12+
get y() {
13+
return y;
14+
},
15+
set y(value) {
16+
y = value;
17+
}
18+
}
19+
</script>
20+
21+
<Child {klass} {getter_setter} />

0 commit comments

Comments
 (0)