angular/packages/zone.js/test
arturovt eddca4280b fix(zone.js): allow draining microtasks in Promise.then (through flag)
These changes are essentially the same as those introduced in
angular#45273, but they include backward compatibility
for applications that explicitly rely on the order in which microtasks are drained.

This is critically important for our code and other third-party code, which is
beyond our control, to work properly. If a microtask is scheduled within an event
listener to be executed "later", it should indeed be executed later and not synchronously,
as this would break the expected flow of code execution.

The simple code that reproduces the behavior that exists now:

```ts
Zone.current.fork({name: 'child'}).run(() => {
  const div = document.createElement('div');
  div.style.height = '200px';
  div.style.width = '200px';
  div.style.backgroundColor = 'red';
  document.body.appendChild(div);

  function listener() {
    Promise.resolve().then(() => {
      div.style.height = '400px';
    });
  }

  div.addEventListener('fakeEvent', listener);
  div.dispatchEvent(new Event('fakeEvent'));
  console.log(div.getBoundingClientRect().height); // 400
});
```

The code above logs 400 as the height, but it should actually log 200 because the
height is updated in a microtask within the event listener.

When using Angular with microfrontend applications, especially when other apps might be
using React, zone.js can disrupt the classical order of operations. For example, when using a
`react-component/trigger`, it schedules a microtask within an event listener using
`Promise.resolve().then(...)` to determine whether the event needs to be re-dispatched.
The event is re-dispatched when the layout has changed, which is why a microtask is used.

With this change, we introduce a global configuration flag,
`__zone_symbol__enable_native_microtask_draining`, to allow consumers to enable
microtask draining within a browser microtask.

This flag is necessary to prevent any breaking changes resulting from this modification.
The previous attempt to address this issue caused a significant number of failures in g3.
Therefore, we are hiding that fix behind the configuration flag.

Closes angular#44446
Closes angular#55590
Closes angular#51328

(cherry picked from commit fc6a7eea68)
2026-04-15 10:31:33 -04:00
..
assets refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
browser test: remove duplicate tests 2026-03-11 13:35:26 -07:00
closure build: separate zone.js dependencies into their own directory (#63425) 2025-09-05 12:52:55 -07:00
common fix(zone.js): allow draining microtasks in Promise.then (through flag) 2026-04-15 10:31:33 -04:00
extra build: update repository to use node 22.21.1 in bazel 2025-12-09 09:19:13 -08:00
jest build: update jest monorepo to v30 (#62234) 2025-06-24 10:49:30 +00:00
node build: migrate zone.js to use ts_project instead of ts_library (#62673) 2025-07-17 13:59:37 -04:00
npm_package refactor(zone.js): remove legacy browser support (#63511) 2025-10-16 14:58:45 +00:00
patch refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
performance ci: reformat files 2025-12-16 09:24:36 -08:00
promise ci: reformat files 2025-12-16 14:44:19 -08:00
rxjs refactor(common): update copyright to Google LLC 2026-02-09 07:51:36 -08:00
typings build: update cross-repo angular dependencies 2026-03-25 12:59:42 -07:00
vitest fix(zone.js): waitForAsync should pass args to the test function (#61755) 2025-06-09 11:22:22 -07:00
webdriver build: enable angular formatting on all html files 2025-12-08 10:19:45 -08:00
zone-spec ci: reformat files 2025-12-16 14:44:19 -08:00
browser-env-setup.ts refactor(zone.js): updates fake polyfill to remove top-level side effect (#53443) 2024-03-15 18:11:34 -07:00
browser-zone-setup.ts refactor(zone.js): remove legacy browser support (#63511) 2025-10-16 14:58:45 +00:00
browser_disable_wrap_uncaught_promise_rejection_entry_point.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
browser_disable_wrap_uncaught_promise_rejection_setup.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
browser_entry_point.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
browser_es2015_entry_point.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
browser_shadydom_entry_point.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
browser_shadydom_setup.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
browser_symbol_setup.ts fix(zone.js): disable wrapping unhandled promise error by default (#52492) 2023-11-03 09:33:20 -07:00
BUILD.bazel refactor(zone.js): remove legacy browser support (#63511) 2025-10-16 14:58:45 +00:00
common_tests.ts build: move from using rollup to esbuild for bundling zone.js (#62775) 2025-07-25 16:53:00 +02:00
fake_entry.js
jasmine-patch.spec.ts build: move from using rollup to esbuild for bundling zone.js (#62775) 2025-07-25 16:53:00 +02:00
karma_test.bzl build: separate zone.js dependencies into their own directory (#63425) 2025-09-05 12:52:55 -07:00
main.ts build: update to bazel 7.6.0 (#63096) 2025-08-14 13:01:30 +02:00
mocha-patch.spec.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
node-env-setup.ts refactor(zone.js): update Node test entry point to call patch functions (#53443) 2024-03-15 18:11:34 -07:00
node_bluebird_entry_point.init.ts refactor(zone.js): remove unused jasmine globalerror monkey patching. (#63077) 2025-08-11 16:41:09 -07:00
node_entry_point.init.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
node_error_disable_policy.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
node_error_disable_policy_entry_point.init.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
node_error_entry_point.init.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
node_error_lazy_policy.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
node_error_lazy_policy_entry_point.init.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
node_tests.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
saucelabs.js refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
test-env-setup-jasmine.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
test-env-setup-mocha.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
test-util.ts refactor(zone.js): remove legacy browser support (#63511) 2025-10-16 14:58:45 +00:00
test_fake_polyfill.ts fix(zone.js): support passthrough of Promise.try API 2026-02-17 11:32:49 -08:00
ws-server.js refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
ws-webworker-context.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
wtf_mock.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
zone_worker_entry_point.ts refactor(zone.js): remove legacy browser support (#63511) 2025-10-16 14:58:45 +00:00