Skip to content

Wrong value of currentZone inside onInvoke hook #31641

@iwonz

Description

@iwonz

Hi!

I decided to write a demo to better understand the mechanism of parentDelegate.
Demo: https://stackblitz.com/edit/angular-zone-js-on-invoke-current-zone

In short, I have three zones and onInvoke in their ZoneSpec.
I expect that currentZone.name inside each onInvoke will give me the name of the zone in which onInvoke was defined.
All good but if define onInvoke only in the first zone, the result will become unexpectedly for me.

I found this bug angular/zone.js#538 and pull request what fixed it. I ran the test from this PR (https://github.com/angular/zone.js/blob/master/test/common/zone.spec.ts#L38-L59) with my example and got an error.

image

Spec with my example

const zone = Zone.current;
const zoneA = zone.fork({
  name: 'A',
  onInvoke: function(
    parentDelegate, currentZone, targetZone, callback, applyThis, applyArgs, source) {
    expect(currentZone.name).toEqual('A');
    return parentDelegate.invoke(targetZone, callback, applyThis, applyArgs, source);
  }
});
const zoneB = zoneA.fork({
  name: 'B'
});
const zoneC = zoneB.fork({name: 'C'});
zoneC.run(function() {});

Where is my mistake?

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