fix: dynamic event delegation for stateful call expressions (#12549)

pull/12557/head
Dominic Gannaway 4 months ago committed by GitHub
parent 55400fd16c
commit 90d6f573e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: dynamic event delegation for stateful call expressions

@ -1169,7 +1169,11 @@ function serialize_event_handler(node, { state, visit }) {
} else { } else {
handler = /** @type {Expression} */ (visit(handler)); handler = /** @type {Expression} */ (visit(handler));
} }
} else if (handler.type === 'ConditionalExpression' || handler.type === 'LogicalExpression') { } else if (
handler.type === 'CallExpression' ||
handler.type === 'ConditionalExpression' ||
handler.type === 'LogicalExpression'
) {
handler = dynamic_handler(); handler = dynamic_handler();
} else { } else {
handler = /** @type {Expression} */ (visit(handler)); handler = /** @type {Expression} */ (visit(handler));

@ -0,0 +1,24 @@
import { flushSync } from 'svelte';
import { test, ok } from '../../test';
export default test({
mode: ['client'],
async test({ assert, target, logs }) {
const [btn1, btn2, btn3] = target.querySelectorAll('button');
flushSync(() => {
btn1.click();
btn2.click();
});
assert.deepEqual(logs, ['AA', 'AB']);
flushSync(() => {
btn3.click();
btn1.click();
btn2.click();
});
assert.deepEqual(logs, ['AA', 'AB', 'BA', 'BB']);
}
});

@ -0,0 +1,15 @@
<script>
let hof = $state((name) => () => console.log('A' + name));
const member = $derived({
hof
});
function change() {
hof = (name) => () => console.log('B' + name);
}
</script>
<button onclick={hof('A')}>A</button>
<button onclick={member.hof('B')}>B</button>
<br />
<button onclick={change}>change</button>
Loading…
Cancel
Save