mirror of https://github.com/sveltejs/svelte
fix: react to mutated slot props in legacy mode (#10197)
If a list is passed to a component and an item of that list is passed as a slot prop back up, then mutating a property of that item did not result in a rerun. The reason was that derived is using object identity equality, resulting in the value not being updated. To fix it, we use safe-equals in this situations instead.pull/10188/head
parent
b94d72bbfb
commit
db8cba3216
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"svelte": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: react to mutated slot props in legacy mode
|
@ -0,0 +1,9 @@
|
|||||||
|
<script>
|
||||||
|
export let things;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{#each things as thing}
|
||||||
|
<slot {thing}/>
|
||||||
|
{/each}
|
||||||
|
</div>
|
@ -0,0 +1,25 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
html: `
|
||||||
|
<button>mutate</button>
|
||||||
|
<div>
|
||||||
|
<span>hello</span>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
|
||||||
|
async test({ assert, target }) {
|
||||||
|
target.querySelector('button')?.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>mutate</button>
|
||||||
|
<div>
|
||||||
|
<span>bye</span>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,10 @@
|
|||||||
|
<script>
|
||||||
|
import Nested from './Nested.svelte';
|
||||||
|
|
||||||
|
let things = [{ text: 'hello' }];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button on:click={() => things[0].text = 'bye'}>mutate</button>
|
||||||
|
<Nested {things} let:thing>
|
||||||
|
<span>{thing.text}</span>
|
||||||
|
</Nested>
|
Loading…
Reference in new issue