angular/packages/zone.js/lib
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
..
browser refactor(zone.js): remove legacy browser support (#63511) 2025-10-16 14:58:45 +00:00
common fix(zone.js): support passthrough of Promise.try API 2026-02-17 11:32:49 -08:00
extra refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
jasmine fix(zone.js): Support jasmine v6 2025-10-24 18:46:04 +02:00
jest refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
mix refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
mocha refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
node refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
rxjs refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
testing refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
zone-spec refactor(zone.js): Improve missing proxy zone error for jest imported (#64497) 2025-10-22 23:26:23 +00:00
BUILD.bazel refactor(zone.js): remove legacy browser support (#63511) 2025-10-16 14:58:45 +00:00
zone-global.d.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
zone-impl.ts fix(zone.js): allow draining microtasks in Promise.then (through flag) 2026-04-15 10:31:33 -04:00
zone.api.extensions.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
zone.configurations.api.ts fix(zone.js): allow draining microtasks in Promise.then (through flag) 2026-04-15 10:31:33 -04:00
zone.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00