fix(core): make sure onStable runs in the right zone (#18706)
Make sure the callbacks to the NgZone callbacks run in the right zone
with or without the rxjs Zone patch -
1ed83d08ac
.
PR Close #18706
This commit is contained in:
parent
079d884b6c
commit
713d7c2360
|
@ -455,7 +455,11 @@ export class ApplicationRef_ extends ApplicationRef {
|
||||||
});
|
});
|
||||||
|
|
||||||
const isStable = new Observable<boolean>((observer: Observer<boolean>) => {
|
const isStable = new Observable<boolean>((observer: Observer<boolean>) => {
|
||||||
const stableSub: Subscription = this._zone.onStable.subscribe(() => {
|
// Create the subscription to onStable outside the Angular Zone so that
|
||||||
|
// the callback is run outside the Angular Zone.
|
||||||
|
let stableSub: Subscription;
|
||||||
|
this._zone.runOutsideAngular(() => {
|
||||||
|
stableSub = this._zone.onStable.subscribe(() => {
|
||||||
NgZone.assertNotInAngularZone();
|
NgZone.assertNotInAngularZone();
|
||||||
|
|
||||||
// Check whether there are no pending macro/micro tasks in the next tick
|
// Check whether there are no pending macro/micro tasks in the next tick
|
||||||
|
@ -468,6 +472,7 @@ export class ApplicationRef_ extends ApplicationRef {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const unstableSub: Subscription = this._zone.onUnstable.subscribe(() => {
|
const unstableSub: Subscription = this._zone.onUnstable.subscribe(() => {
|
||||||
NgZone.assertInAngularZone();
|
NgZone.assertInAngularZone();
|
||||||
|
|
|
@ -62,6 +62,9 @@ export class ComponentFixture<T> {
|
||||||
this.ngZone = ngZone;
|
this.ngZone = ngZone;
|
||||||
|
|
||||||
if (ngZone) {
|
if (ngZone) {
|
||||||
|
// Create subscriptions outside the NgZone so that the callbacks run oustide
|
||||||
|
// of NgZone.
|
||||||
|
ngZone.runOutsideAngular(() => {
|
||||||
this._onUnstableSubscription =
|
this._onUnstableSubscription =
|
||||||
ngZone.onUnstable.subscribe({next: () => { this._isStable = false; }});
|
ngZone.onUnstable.subscribe({next: () => { this._isStable = false; }});
|
||||||
this._onMicrotaskEmptySubscription = ngZone.onMicrotaskEmpty.subscribe({
|
this._onMicrotaskEmptySubscription = ngZone.onMicrotaskEmpty.subscribe({
|
||||||
|
@ -96,6 +99,7 @@ export class ComponentFixture<T> {
|
||||||
|
|
||||||
this._onErrorSubscription =
|
this._onErrorSubscription =
|
||||||
ngZone.onError.subscribe({next: (error: any) => { throw error; }});
|
ngZone.onError.subscribe({next: (error: any) => { throw error; }});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue