-
-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dispatchEvent
fired events don't bubble
#1661
Comments
Thank you for reporting @raystubbs! 🙂 I can't reproduce this issue in the latest version of Happy DOM. Could the problem be that the console used is the default VirtualConsole, and therefore it is not printed out to the Node.js console? You can change to use the Node.js console like this: const window = new Window({ console: globalThis.console }); If this doesn't solve your problem, please try with the latest version v16.3.0 |
Please re-open if you believe that the issue hasn't been solved. |
Huh, odd, I'll investigate further and get back to you. |
This is still definitely happening on my end. I'm on node 18, just downgraded from 21 to see if it was a version issue. But seeing this in both of them. Here's my repro code: const { Window } = require('happy-dom');
const window = new Window();
window.document.body.innerHTML = "<div><button>Click Me!</button></div>";
const div = window.document.querySelector("div");
const btn = window.document.querySelector("button");
for(const node of [div, btn]) {
node.addEventListener("click", () => {
console.log("click", node.nodeName);
});
node.addEventListener("a", () => {
console.log("a", node.nodeName);
});
node.addEventListener("b", () => {
console.log("b", node.nodeName);
});
node.addEventListener("c", () => {
console.log("c", node.nodeName);
});
}
btn.click();
btn.dispatchEvent(new Event("a", {bubbles: true}));
btn.dispatchEvent(new Event("b", {bubbles: true}));
btn.dispatchEvent(new Event("c", {bubbles: true}));
console.log("done"); And the output:
And my
|
I don't think Github will let me reopen this once it's been closed by the repo owner @capricorn86. |
Re-opened 😊 |
Thanks 🙏 |
I'm still not able to reproduce the problem. I'm not sure if I have missed something. You are sure that you are running with a newer version of Happy DOM? I have added your test as a unit test: The output there is:
Which seem to be correct. By the way, thank you for sponsoring me and Happy DOM! 🙏 |
Huh... that's very odd. That output seems right to me... which seems to indicate that whatever's going on is specific to my setup. I'll try cloning and running all the unit tests. See if they break on my system.
My absolute pleasure! Isn't much. But I use Happy DOM quite a bit these days, and think it's an awesome project. Wanted to give what I could to show some appreciation. |
Eh, my bad 😅 sorry for wasting your time and mine; I was dispatching instances of the wrong event class. |
Describe the bug
Events fired with
dispatchEvent
don't propagate up the DOM.To Reproduce
Steps to reproduce the behavior:
<div id="my-div"><button id="my-button"></button></div>
document.querySelector("#my-div").addEventListener("my-event", event => console.log(event))
document.querySelector("#my-button").dispatchEvent(new Event("my-event", {bubbles: true}))
Expected behavior
The event should bubble up to
#my-div
, and be printed by the listener. But that doesn't happen.Device:
The text was updated successfully, but these errors were encountered: