Describe the bug
addEvent() accepts EventListenerObject handlers, but delegated event dispatch assumes every handler is a function and calls handler.call(...).
When an object with handleEvent() is used for a delegated event such as click, dispatch throws:
TypeError: handler.call is not a function
The same handler shape works for non-delegated events because it is passed directly to the native addEventListener().
Steps to Reproduce the Bug or Issue
import {
addEvent,
delegateEvents,
render
} from "@solidjs/web";
const container = document.createElement("div");
const button = document.createElement("button");
document.body.append(container);
const calls: Event[] = [];
const listener = {
handleEvent(event: Event) {
calls.push(event);
}
};
const dispose = render(() => button, container);
addEvent(button, "click", listener, true);
delegateEvents(["click"]);
button.click();
// Expected: 1
// Actual: 0, and dispatch throws:
// TypeError: handler.call is not a function
console.log(calls.length);
dispose();
container.remove();
Expected behavior
The delegated event dispatcher should invoke:
listener.handleEvent(event);
This would match the native EventTarget behavior and the EventListenerObject type accepted by addEvent().
Additional context
Type check in the delegated dispatcher makes the regression test pass:
if (typeof handler === "function") {
handler.call(node, event);
} else {
handler.handleEvent(event);
}
Describe the bug
addEvent()acceptsEventListenerObjecthandlers, but delegated event dispatch assumes every handler is a function and callshandler.call(...).When an object with
handleEvent()is used for a delegated event such asclick, dispatch throws:The same handler shape works for non-delegated events because it is passed directly to the native addEventListener().
Steps to Reproduce the Bug or Issue
Expected behavior
The delegated event dispatcher should invoke:
This would match the native EventTarget behavior and the EventListenerObject type accepted by addEvent().
Additional context
Type check in the delegated dispatcher makes the regression test pass: