fix: remove spreaded event handlers when they become nullish (#14546)

Fixes #14539
pull/14550/head
Paolo Ricciuti 3 weeks ago committed by GitHub
parent 4c4f18b24c
commit 1f973b1770
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: remove spreaded event handlers when they become nullish

@ -281,6 +281,9 @@ export function set_attributes(
element[`__${event_name}`] = value;
delegate([event_name]);
}
} else if (delegated) {
// @ts-ignore
element[`__${event_name}`] = undefined;
}
} else if (key === 'style' && value != null) {
element.style.cssText = value + '';

@ -0,0 +1,32 @@
import { ok, test } from '../../test';
import { flushSync } from 'svelte';
export default test({
async test({ assert, target, instance }) {
const p = target.querySelector('p');
const btn = target.querySelector('button');
const input = target.querySelector('input');
ok(p);
flushSync(() => {
btn?.click();
});
assert.equal(p.innerHTML, '1');
flushSync(() => {
input?.click();
});
flushSync(() => {
btn?.click();
});
assert.equal(p.innerHTML, '1');
flushSync(() => {
input?.click();
});
flushSync(() => {
btn?.click();
});
assert.equal(p.innerHTML, '2');
}
});

@ -0,0 +1,12 @@
<script>
let checked = $state(true)
let count = $state(0)
const onclick = $derived(checked ? (() => { count++ }) : undefined)
</script>
<p>
{count}
</p>
<input type="checkbox" bind:checked />
<button {...{onclick}}></button>
Loading…
Cancel
Save