mirror of https://github.com/sveltejs/svelte
parent
54990f2329
commit
267339e551
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: don't re-`attach` the same function to the same element
|
@ -0,0 +1,19 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
test({ assert, target, logs }) {
|
||||||
|
const p = target.querySelector('p');
|
||||||
|
const btn = target.querySelector('button');
|
||||||
|
|
||||||
|
assert.deepEqual(logs, ['up']);
|
||||||
|
assert.equal(p?.dataset.count, '0');
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
btn?.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(logs, ['up']);
|
||||||
|
assert.equal(p?.dataset.count, '1');
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,21 @@
|
|||||||
|
<script>
|
||||||
|
import { createAttachmentKey } from "svelte/attachments";
|
||||||
|
|
||||||
|
let count = $state(0);
|
||||||
|
|
||||||
|
const attachment = () => {
|
||||||
|
console.log("up");
|
||||||
|
return () => {
|
||||||
|
console.log("down");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = $derived({
|
||||||
|
'data-count': count,
|
||||||
|
[createAttachmentKey()]: attachment
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p {...props}></p>
|
||||||
|
|
||||||
|
<button onclick={() => count++}>{count}</button>
|
Loading…
Reference in new issue