Skip to content

Commit 3a86940

Browse files
JiaLiPassionalxhub
authored andcommitted
fix(core): should check Zone existance when scheduleMicroTask (#20656)
PR Close #20656
1 parent 7b120b5 commit 3a86940

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/core/src/util.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'unde
2121
self instanceof WorkerGlobalScope && self;
2222
const __global = typeof global !== 'undefined' && global;
2323
const _global: {[name: string]: any} = __window || __global || __self;
24+
25+
const promise: Promise<any> = Promise.resolve(0);
2426
/**
2527
* Attention: whenever providing a new value, be sure to add an
2628
* entry into the corresponding `....externs.js` file,
@@ -52,7 +54,12 @@ export function getSymbolIterator(): string|symbol {
5254
}
5355

5456
export function scheduleMicroTask(fn: Function) {
55-
Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
57+
if (typeof Zone === 'undefined') {
58+
// use promise to schedule microTask instead of use Zone
59+
promise.then(() => { fn && fn.apply(null, null); });
60+
} else {
61+
Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
62+
}
5663
}
5764

5865
// JS has NaN !== NaN

packages/platform-browser/animations/src/animation_renderer.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class AnimationRendererFactory implements RendererFactory2 {
1919
private _animationCallbacksBuffer: [(e: any) => any, any][] = [];
2020
private _rendererCache = new Map<Renderer2, BaseAnimationRenderer>();
2121
private _cdRecurDepth = 0;
22+
private promise: Promise<any> = Promise.resolve(0);
2223

2324
constructor(
2425
private delegate: RendererFactory2, private engine: AnimationEngine, private _zone: NgZone) {
@@ -69,7 +70,8 @@ export class AnimationRendererFactory implements RendererFactory2 {
6970
}
7071

7172
private _scheduleCountTask() {
72-
Zone.current.scheduleMicroTask('incremenet the animation microtask', () => this._microtaskId++);
73+
// always use promise to schedule microtask instead of use Zone
74+
this.promise.then(() => { this._microtaskId++; });
7375
}
7476

7577
/* @internal */

0 commit comments

Comments
 (0)