Skip to content

[zonejs] An exception in event handler breaks execution of remaining handlers #41522

@mleibman

Description

@mleibman

🐞 bug report

Affected Package

The issue is caused by package @angular/zone.js.

Is this a regression?

AFAICT, it has always been like this.

Description

W3C event handlers are supposed to be called regardless if one of them throws an exception.
However when global callback handling is used (default), if any of the registered event handlers result in an unhandled exception, execution of all remaining handlers is aborted. This represents a significant and hard-to-detect breakage in event handling just from loading ZoneJS.

for (let i = 0; i < copyTasks.length; i++) {
if (event && (event as any)[IMMEDIATE_PROPAGATION_SYMBOL] === true) {
break;
}
invokeTask(copyTasks[i], target, event);
}

🔬 Minimal Reproduction

When run w/o ZoneJS, clicking the button prints both click 1 and click 2.
When run with ZoneJS loaded, only click 1 is printed.

(function() {
  const btn = document.body.appendChild(document.createElement('button'));
  btn.textContent = 'Click me';

  btn.addEventListener('click', () => {
    console.log('click 1');
    throw new Error();
  });

  btn.addEventListener('click', () => {
    console.log('click 2');
  });
})()

Metadata

Metadata

Assignees

Labels

P2The issue is important to a large percentage of users, with a workaroundarea: zonesIssues related to zone.jshotlist: google

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions