diff --git a/.changeset/tough-guests-sniff.md b/.changeset/tough-guests-sniff.md new file mode 100644 index 0000000000..fcb7b67c1a --- /dev/null +++ b/.changeset/tough-guests-sniff.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: silence false-positive stale value warning diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/AssignmentExpression.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/AssignmentExpression.js index 3d8b9aaa96..0c70f7e00c 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/AssignmentExpression.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/AssignmentExpression.js @@ -171,6 +171,7 @@ function build_assignment(operator, left, right, context) { // special case — ignore `bind:prop={getter, (v) => (...)}` / `bind:value={x.y}` if ( + path.at(-1) === 'BindDirective' || path.at(-1) === 'Component' || path.at(-1) === 'SvelteComponent' || (path.at(-1) === 'ArrowFunctionExpression' && diff --git a/packages/svelte/tests/runtime-runes/samples/proxy-coercive-assignment-warning/_config.js b/packages/svelte/tests/runtime-runes/samples/proxy-coercive-assignment-warning/_config.js index ad7bdc654a..f029227472 100644 --- a/packages/svelte/tests/runtime-runes/samples/proxy-coercive-assignment-warning/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/proxy-coercive-assignment-warning/_config.js @@ -1,21 +1,33 @@ import { flushSync } from 'svelte'; -import { test } from '../../test'; +import { ok, test } from '../../test'; export default test({ compileOptions: { dev: true }, - html: `
x
`, + html: `
x
`, test({ assert, target, warnings }) { const btn = target.querySelector('button'); + ok(btn); - flushSync(() => btn?.click()); - assert.htmlEqual(target.innerHTML, `
x
`); + flushSync(() => btn.click()); + assert.htmlEqual( + target.innerHTML, + `
x
` + ); - flushSync(() => btn?.click()); - assert.htmlEqual(target.innerHTML, `
x
`); + flushSync(() => btn.click()); + assert.htmlEqual( + target.innerHTML, + `
x
` + ); + + const input = target.querySelector('input'); + ok(input); + input.checked = true; + flushSync(() => input.dispatchEvent(new Event('change', { bubbles: true }))); assert.deepEqual(warnings, [ '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.' diff --git a/packages/svelte/tests/runtime-runes/samples/proxy-coercive-assignment-warning/main.svelte b/packages/svelte/tests/runtime-runes/samples/proxy-coercive-assignment-warning/main.svelte index 40592e08b8..ad94c4e56e 100644 --- a/packages/svelte/tests/runtime-runes/samples/proxy-coercive-assignment-warning/main.svelte +++ b/packages/svelte/tests/runtime-runes/samples/proxy-coercive-assignment-warning/main.svelte @@ -2,7 +2,7 @@ import Test from './Test.svelte'; let entries = $state([]); - let object = $state({ items: null }); + let object = $state({ items: null, group: [] });