Skip to content

Events created with new Event() don't bubble to parent elements #2054

@dy

Description

@dy

Events created using the Event constructor with { bubbles: true } do not bubble to parent elements, even though event.bubbles is correctly set to true.

Reproduction

const { Window } = require('happy-dom');
const window = new Window();
const document = window.document;

const parent = document.createElement('div');
const child = document.createElement('span');
parent.appendChild(child);
document.body.appendChild(parent);

let bubbled = false;
parent.addEventListener('click', () => {
  bubbled = true;
});

const event = new Event('click', { bubbles: true });
console.log('event.bubbles:', event.bubbles); // true ✓

child.dispatchEvent(event);
console.log('bubbled to parent:', bubbled); // false ✗ (should be true)

Expected behavior

The event should bubble from child to parent, triggering the parent's event listener.

Actual behavior

  • event.bubbles is correctly true
  • Event fires on child
  • Event does NOT bubble to parent
  • Parent's listener is never called

Workaround

Using the legacy createEvent/initEvent API works correctly:

const event = document.createEvent('Event');
event.initEvent('click', true, true); // (type, bubbles, cancelable)
child.dispatchEvent(event);
console.log('bubbled to parent:', bubbled); // true ✓

Impact

This breaks any code using the modern Event constructor API for custom events or synthetic event dispatching. Many testing libraries and frameworks rely on this for simulating user interactions.

Environment

  • happy-dom version: 16.7.2
  • Node.js version: v22.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions