Skip to content

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

Closed

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.

Activity

  1. added this to the needsTriage milestone on Dec 11, 2021
  2. self-assigned this
    on Feb 20, 2022
  3. JiaLiPassion commented on Feb 20, 2022

    @JiaLiPassion
    Contributor

    @xiaody , yes, this is a known issue, and may not be fixed in the near future, it there any real world application has some issues because this behavior?

  4. xiaody commented on Feb 23, 2022

    @xiaody
    Author

    React's invokeGuardedCallbackImpl uses such pattern, it creates a fakeNode, add a listener on it and dispatch an event synchronously. #41506(with old version antd) maybe a real world case as I have commented there.

  5. added a commit that references this issue on Jun 8, 2022
  6. added
    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
    on Nov 16, 2022
  7. modified the milestones: needsTriage, Backlog on Nov 16, 2022
  8. added a commit that references this issue on Apr 1, 2024
    a37c469
  9. 12 remaining items

  10. added 3 commits that reference this issue on Apr 10, 2026
    948ccc7
    acf8233
    45a4650
  11. added a commit that references this issue on Apr 15, 2026
    eddca42
  12. added a commit that references this issue on Apr 15, 2026
    fc6a7ee
  13. angular-automatic-lock-bot commented on May 16, 2026

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  14. locked and limited conversation to collaborators on May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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