Skip to content

zone.js drains microtasks too early in synchronous event call #44446

Description

@xiaody

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

Don't known / other

Is this a regression?

No

Description

Please see the reproduction. It seems zone.js assumes EventTarget's event call is always a standalone task, which may not be true.

const invoke = (fn) => {
  document.body.addEventListener('click', fn);
  document.body.click();
  document.body.removeEventListener('click', fn);
};

invoke(() => {
  Promise.resolve().then(() => console.log(2));
});
console.log(1);

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/typescript-88btqj?file=index.ts

Please provide the exception or error you saw

Native Chrome/Safari/Firefox outputs `1 2`, while with zone.js outputs `2 1`.

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

No response

Anything else?

I noticed this during debugging #41506 (comment) , maybe related.

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: zonesIssues related to zone.jsstate: has PR

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions