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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 4 additions & 3 deletions
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}`);
Lines changed: 18 additions & 0 deletions
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+
});
Lines changed: 8 additions & 0 deletions
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>
Lines changed: 21 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy