fix: don't throw for `undefined` non delegated event handlers (#15087)

* fix: don't throw for `undefined` non delegated event handlers

* chore: update typings
pull/15057/head
Paolo Ricciuti 8 months ago committed by GitHub
parent ee024ffd0e
commit 7da86ef80c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: don't throw for `undefined` non delegated event handlers

@ -49,10 +49,10 @@ export function replay_events(dom) {
/**
* @param {string} event_name
* @param {EventTarget} dom
* @param {EventListener} handler
* @param {AddEventListenerOptions} options
* @param {EventListener} [handler]
* @param {AddEventListenerOptions} [options]
*/
export function create_event(event_name, dom, handler, options) {
export function create_event(event_name, dom, handler, options = {}) {
/**
* @this {EventTarget}
*/
@ -63,7 +63,7 @@ export function create_event(event_name, dom, handler, options) {
}
if (!event.cancelBubble) {
return without_reactive_context(() => {
return handler.call(this, event);
return handler?.call(this, event);
});
}
}
@ -108,8 +108,8 @@ export function on(element, type, handler, options = {}) {
/**
* @param {string} event_name
* @param {Element} dom
* @param {EventListener} handler
* @param {boolean} capture
* @param {EventListener} [handler]
* @param {boolean} [capture]
* @param {boolean} [passive]
* @returns {void}
*/

@ -0,0 +1,9 @@
import { ok, test } from '../../test';
export default test({
async test({ target }) {
const button = target.querySelector('button');
ok(button);
button.dispatchEvent(new window.MouseEvent('mouseenter'));
}
});
Loading…
Cancel
Save