mirror of https://github.com/sveltejs/svelte
fix: improve key block reactivity detection (#10092)
parent
86eae7e77d
commit
ddd7926240
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: improve key block reactivity detection
|
@ -0,0 +1,39 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<p>test costs $1</p><p>test 2 costs $2</p><p>test costs $1</p><p>test 2 costs $2</p><button>add</button><button>change</button><button>reload</button>`,
|
||||
skip_if_ssr: 'permanent',
|
||||
skip_if_hydrate: 'permanent',
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [btn1, btn2, btn3] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => {
|
||||
btn2.click();
|
||||
});
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<p>test costs $1</p><p>test 2 costs $2000</p><p>test costs $1</p><p>test 2 costs $2000</p><button>add</button><button>change</button><button>reload</button>`
|
||||
);
|
||||
|
||||
flushSync(() => {
|
||||
btn1.click();
|
||||
});
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<p>test costs $1</p><p>test 2 costs $2000</p><p>test 3 costs $3</p><p>test costs $1</p><p>test 2 costs $2000</p><p>test 3 costs $3</p><button>add</button><button>change</button><button>reload</button>`
|
||||
);
|
||||
|
||||
flushSync(() => {
|
||||
btn3.click();
|
||||
});
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<p>test costs $1</p><p>test 2 costs $2000</p><p>test costs $1</p><p>test 2 costs $2000</p><button>add</button><button>change</button><button>reload</button>`
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,54 @@
|
||||
<script>
|
||||
let data = $state({ items: [] });
|
||||
|
||||
function fetchData() {
|
||||
data = {
|
||||
items: [{
|
||||
id: 1,
|
||||
price: 1,
|
||||
name: 'test'
|
||||
}, {
|
||||
id: 2,
|
||||
price: 2,
|
||||
name: 'test 2'
|
||||
}]
|
||||
};
|
||||
}
|
||||
|
||||
fetchData();
|
||||
|
||||
function copyItems(original) {
|
||||
return [...original.map((item) => ({ ...item }))];
|
||||
}
|
||||
|
||||
let items = $state();
|
||||
|
||||
$effect(() => {
|
||||
items = copyItems(data.items);
|
||||
});
|
||||
</script>
|
||||
|
||||
{#each items as item}
|
||||
<p>{item.name} costs ${item.price}</p>
|
||||
{/each}
|
||||
|
||||
{#each items as item (item.id)}
|
||||
<p>{item.name} costs ${item.price}</p>
|
||||
{/each}
|
||||
|
||||
|
||||
<button onclick={() => {
|
||||
items.push({
|
||||
id: 3,
|
||||
price: 3,
|
||||
name: 'test 3'
|
||||
})
|
||||
}}>add</button>
|
||||
|
||||
<button onclick={() => {
|
||||
data.items[1].price = 2000
|
||||
}}>change</button>
|
||||
|
||||
<button onclick={() => {
|
||||
fetchData();
|
||||
}}>reload</button>
|
Loading…
Reference in new issue