Skip to content

Zone.js does not properly handle AbortSignal in addEventListener #49591

@DavidANeil

Description

@DavidANeil

Which @angular/* package(s) are the source of the bug?

zone.js

Is this a regression?

No

Description

Zone.js tries to be clever and creates a single handler for all listeners to the same event on the same target that have the same capture setting.

However, with the somewhat recent addition of the signal setting, this means that handlers can improperly registered, consider the following two tests:

const controller = new AbortController();
window.addEventListener('myEvent', () => console.log('expected'));
window.addEventListener('myEvent', () => console.log('unexpected'), {signal: controller.signal});
controller.abort();
window.dispatchEvent(new Event('myEvent'));
// LOG: 'expected'
// LOG: 'unexpected'
const controller = new AbortController();
window.addEventListener('myEvent', () => console.log('unexpected'), {signal: controller.signal});
window.addEventListener('myEvent', () => console.log('expected'));
controller.abort();
window.dispatchEvent(new Event('myEvent'));
// nothing logs

If zone.js is not installed, only 'expected' is logged in each case.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

No response

Anything else?

No response

Metadata

Metadata

Assignees

Labels

area: zonesIssues related to zone.js

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions