mirror of https://github.com/sveltejs/svelte
fix: handle component binding mutation (#10786)
* fix: handle component binding mutation https://github.com/sveltejs/svelte/issues/10359#issuecomment-1991885046 * alternative approach to mutating props (#10788) Co-authored-by: Rich Harris <rich.harris@vercel.com> --------- Co-authored-by: Rich Harris <richard.a.harris@gmail.com> Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/10782/head
parent
2cb78ac253
commit
339782f3e0
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: handle component binding mutation
|
@ -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…
Reference in new issue