fix: correctly ensure prop bindings are reactive when bound (#12879)

* fix: correctly ensure prop bindings are reactive when bound

* oops

* Apply suggestions from code review

* Update packages/svelte/src/compiler/phases/3-transform/client/utils.js

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/12887/head
Dominic Gannaway 1 year ago committed by GitHub
parent cb75b5c966
commit 94ed09628d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: correctly ensure prop bindings are reactive when bound

@ -186,7 +186,7 @@ export function get_prop_source(binding, state, name, initial) {
state.analysis.accessors ||
(state.analysis.immutable
? binding.reassigned || (state.analysis.runes && binding.mutated)
: binding.mutated)
: binding.updated)
) {
flags |= PROPS_IS_UPDATED;
}

@ -0,0 +1,5 @@
<script>
export let value;
</script>
<input type="text" bind:value />

@ -0,0 +1,22 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';
export default test({
accessors: false,
html: `<input type="text">\naaa`,
ssrHtml: `<input type="text" value="aaa">\naaa`,
test({ assert, target }) {
const input = target.querySelector('input');
ok(input);
const event = new window.Event('input');
input.value = 'aaa2';
input.dispatchEvent(event);
flushSync();
assert.htmlEqual(target.innerHTML, `<input type="text">\naaa2`);
}
});

@ -0,0 +1,9 @@
<script>
import Field from './Field.svelte';
import { writable } from 'svelte/store';
const value = writable('aaa');
</script>
<Field bind:value={$value} /> {$value}
Loading…
Cancel
Save