Issue
We use a Angular cell component which contains a button. I noticed that sometimes (approximately 1 out of 10 times) the button event is handled outside of the zone which leads to issues.
What I've found out so far
agInit sometimes runs outside of the zone. I found that out by using the following snippet:
agInit(params: RendererParams): void {
const inZone = NgZone.isInAngularZone();
console.log("AgInit in Zone?: " + inZone);
}
If agInit is not in the angular zone, the button callback is also not in the zone.
I also noticed that the callstack is slightly different in the case where agInit runs inside our outside the zone:
Here is a link to a full diff of both stack traces: https://www.diffchecker.com/e54rZEsC
I also noticed that in the error case, the callstack start from Utils.debounce in agGrid.
To further investigate the issue, I forked the ngzone (see snippet below). No errors were logged.
ngDoBootstrap(applicationRef: ApplicationRef) {
const debugSpec: ZoneSpec = {
name: "debugSpec",
onHandleError: (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, error: any) => {
console.log(error);
return true;
}
};
Zone.current.fork(debugSpec).run(() => {
applicationRef.bootstrap(AppComponent);
});
}
Workaround
I can always manually run the callback within the zone. That works.