Skip to content

Commit e87fadc

Browse files
committed
fix: silence false-positive statel value warning
fixes #14687
1 parent deb362f commit e87fadc

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

.changeset/tough-guests-sniff.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: silence false-positive stale value warning

packages/svelte/src/compiler/phases/3-transform/client/visitors/AssignmentExpression.js

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ function build_assignment(operator, left, right, context) {
171171

172172
// special case — ignore `bind:prop={getter, (v) => (...)}` / `bind:value={x.y}`
173173
if (
174+
path.at(-1) === 'BindDirective' ||
174175
path.at(-1) === 'Component' ||
175176
path.at(-1) === 'SvelteComponent' ||
176177
(path.at(-1) === 'ArrowFunctionExpression' &&

packages/svelte/tests/runtime-runes/samples/proxy-coercive-assignment-warning/_config.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
import { flushSync } from 'svelte';
2-
import { test } from '../../test';
2+
import { ok, test } from '../../test';
33

44
export default test({
55
compileOptions: {
66
dev: true
77
},
88

9-
html: `<button>items: null</button> <div>x</div>`,
9+
html: `<button>items: null</button> <div>x</div> <input type="checkbox" value="1"><input type="checkbox" value="2">`,
1010

1111
test({ assert, target, warnings }) {
1212
const btn = target.querySelector('button');
13+
ok(btn);
1314

14-
flushSync(() => btn?.click());
15-
assert.htmlEqual(target.innerHTML, `<button>items: []</button> <div>x</div>`);
15+
flushSync(() => btn.click());
16+
assert.htmlEqual(
17+
target.innerHTML,
18+
`<button>items: []</button> <div>x</div> <input type="checkbox" value="1"><input type="checkbox" value="2">`
19+
);
1620

17-
flushSync(() => btn?.click());
18-
assert.htmlEqual(target.innerHTML, `<button>items: [0]</button> <div>x</div>`);
21+
flushSync(() => btn.click());
22+
assert.htmlEqual(
23+
target.innerHTML,
24+
`<button>items: [0]</button> <div>x</div> <input type="checkbox" value="1"><input type="checkbox" value="2">`
25+
);
26+
27+
const input = target.querySelector('input');
28+
ok(input);
29+
input.checked = true;
30+
flushSync(() => input.dispatchEvent(new Event('change', { bubbles: true })));
1931

2032
assert.deepEqual(warnings, [
2133
'Assignment to `items` property (main.svelte:8:24) will evaluate to the right-hand side, not the value of `items` following the assignment. This may result in unexpected behaviour.'

packages/svelte/tests/runtime-runes/samples/proxy-coercive-assignment-warning/main.svelte

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import Test from './Test.svelte';
33
44
let entries = $state([]);
5-
let object = $state({ items: null });
5+
let object = $state({ items: null, group: [] });
66
</script>
77

88
<button onclick={() => (object.items ??= []).push(object.items.length)}>
@@ -11,6 +11,8 @@
1111

1212
<!-- these should not emit warnings -->
1313
<div bind:this={entries[0]}>x</div>
14+
<input type="checkbox" value=1 bind:group={object.group}>
15+
<input type="checkbox" value=2 bind:group={object.group}>
1416
<Test bind:this={entries[1]}></Test>
1517
<Test bind:this={() => entries[2], (v) => (entries[2] = v)}></Test>
1618
<Test bind:x={entries[3]}></Test>

0 commit comments

Comments
 (0)