fix(core): should check Zone existance when scheduleMicroTask (#20656)
PR Close #20656
This commit is contained in:
parent
7b120b5f73
commit
3a86940ca5
|
@ -21,6 +21,8 @@ const __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'unde
|
|||
self instanceof WorkerGlobalScope && self;
|
||||
const __global = typeof global !== 'undefined' && global;
|
||||
const _global: {[name: string]: any} = __window || __global || __self;
|
||||
|
||||
const promise: Promise<any> = Promise.resolve(0);
|
||||
/**
|
||||
* Attention: whenever providing a new value, be sure to add an
|
||||
* entry into the corresponding `....externs.js` file,
|
||||
|
@ -52,7 +54,12 @@ export function getSymbolIterator(): string|symbol {
|
|||
}
|
||||
|
||||
export function scheduleMicroTask(fn: Function) {
|
||||
if (typeof Zone === 'undefined') {
|
||||
// use promise to schedule microTask instead of use Zone
|
||||
promise.then(() => { fn && fn.apply(null, null); });
|
||||
} else {
|
||||
Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
|
||||
}
|
||||
}
|
||||
|
||||
// JS has NaN !== NaN
|
||||
|
|
|
@ -19,6 +19,7 @@ export class AnimationRendererFactory implements RendererFactory2 {
|
|||
private _animationCallbacksBuffer: [(e: any) => any, any][] = [];
|
||||
private _rendererCache = new Map<Renderer2, BaseAnimationRenderer>();
|
||||
private _cdRecurDepth = 0;
|
||||
private promise: Promise<any> = Promise.resolve(0);
|
||||
|
||||
constructor(
|
||||
private delegate: RendererFactory2, private engine: AnimationEngine, private _zone: NgZone) {
|
||||
|
@ -69,7 +70,8 @@ export class AnimationRendererFactory implements RendererFactory2 {
|
|||
}
|
||||
|
||||
private _scheduleCountTask() {
|
||||
Zone.current.scheduleMicroTask('incremenet the animation microtask', () => this._microtaskId++);
|
||||
// always use promise to schedule microtask instead of use Zone
|
||||
this.promise.then(() => { this._microtaskId++; });
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
|
|
Loading…
Reference in New Issue