mirror of https://github.com/sveltejs/svelte
fix: ensure bind:this unmount behavior for members is conditional (#11193)
* fix: ensure bind:this unmount behavior for members is conditional * revisepull/11196/head
parent
e7869faf4d
commit
77ed790fb3
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"svelte": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: ensure bind:this unmount behavior for members is conditional
|
@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
let { item = $bindable() } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div bind:this={item.dom}>
|
||||||
|
{item.text}
|
||||||
|
</div>
|
@ -0,0 +1,25 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target, component }) {
|
||||||
|
const [b1, b2] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
b1.click();
|
||||||
|
b1.click();
|
||||||
|
b1.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<button>add item</button><button>clear</button><div>Item 1</div><div>Item 2</div><div>Item 3</div>`
|
||||||
|
);
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
b2.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, `<button>add item</button><button>clear</button>`);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,23 @@
|
|||||||
|
<script>
|
||||||
|
import Child from './Child.svelte';
|
||||||
|
let items = $state([]);
|
||||||
|
|
||||||
|
function add_item() {
|
||||||
|
items.push({
|
||||||
|
id: items.length,
|
||||||
|
text: 'Item ' + (items.length + 1),
|
||||||
|
dom: null,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function clear() {
|
||||||
|
items = [];
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button on:click={add_item}>add item</button>
|
||||||
|
<button on:click={clear}>clear</button>
|
||||||
|
|
||||||
|
{#each items as item, index (item.id)}
|
||||||
|
<Child bind:item={items[index]} />
|
||||||
|
{/each}
|
Loading…
Reference in new issue