Simon Holthausen 2 years ago
parent 2cb78ac253
commit 8a7e54065c

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: handle component binding mutation

@ -175,10 +175,13 @@ export function prop(props, key, flags, initial) {
// intermediate mode — prop is written to, but the parent component had
// `bind:foo` which means we can just call `$$props.foo = value` directly
if (setter) {
return function (/** @type {V} */ value) {
return function (/** @type {V} */ value, mutation = false) {
if (arguments.length === 1) {
/** @type {Function} */ (setter)(value);
return value;
} else if (mutation) {
/** @type {Function} */ (setter)(getter());
return value;
} else {
return getter();
}

@ -0,0 +1,5 @@
<script>
export let value;
</script>
<input bind:value={value.name}>

@ -0,0 +1,32 @@
import { ok, test } from '../../test';
export default test({
html: `
<input>
<p>foo</p>
`,
ssrHtml: `
<input value=foo>
<p>foo</p>
`,
async test({ assert, component, target, window }) {
const event = new window.MouseEvent('input');
const input = target.querySelector('input');
ok(input);
input.value = 'blah';
await input.dispatchEvent(event);
await Promise.resolve();
assert.deepEqual(component.deep, { name: 'blah' });
assert.htmlEqual(
target.innerHTML,
`
<input>
<p>blah</p>
`
);
}
});

@ -0,0 +1,11 @@
<script>
import Widget from './Widget.svelte';
export let deep = {
name: 'foo'
};
</script>
<Widget bind:value={deep}/>
<p>{deep.name}</p>
Loading…
Cancel
Save