Skip to content

Commit 8a19aaf

Browse files
committed
fix: don't throw for undefined non delegated event handlers
1 parent 09510c8 commit 8a19aaf

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

.changeset/clever-cherries-hear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: don't throw for `undefined` non delegated event handlers

packages/svelte/src/internal/client/dom/elements/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function create_event(event_name, dom, handler, options) {
6363
}
6464
if (!event.cancelBubble) {
6565
return without_reactive_context(() => {
66-
return handler.call(this, event);
66+
return handler?.call(this, event);
6767
});
6868
}
6969
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ok, test } from '../../test';
2+
3+
export default test({
4+
async test({ target }) {
5+
const button = target.querySelector('button');
6+
ok(button);
7+
button.dispatchEvent(new window.MouseEvent('mouseenter'));
8+
}
9+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<button onmouseenter={undefined}></button>

0 commit comments

Comments
 (0)