diff --git a/src/runtime/internal/Component.ts b/src/runtime/internal/Component.ts index 3e48010547..0e9e4f0610 100644 --- a/src/runtime/internal/Component.ts +++ b/src/runtime/internal/Component.ts @@ -212,6 +212,9 @@ if (typeof HTMLElement === 'function') { $on(type, callback) { // TODO should this delegate to addEventListener? + if (!is_function(callback)) { + return noop; + } const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = [])); callbacks.push(callback); @@ -244,6 +247,9 @@ export class SvelteComponent { } $on(type, callback) { + if (!is_function(callback)) { + return noop; + } const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = [])); callbacks.push(callback); diff --git a/test/runtime/samples/component-events-nullish/Widget.svelte b/test/runtime/samples/component-events-nullish/Widget.svelte new file mode 100644 index 0000000000..07ae574403 --- /dev/null +++ b/test/runtime/samples/component-events-nullish/Widget.svelte @@ -0,0 +1,14 @@ + +