Skip to content

Commit 5471972

Browse files
committed
fix: Guard access to global Zone in case it is undefined
1 parent 56c19f3 commit 5471972

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/zones.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717
} from 'rxjs';
1818
import { observeOn, subscribeOn, tap } from 'rxjs/operators';
1919

20+
declare const Zone: {current: unknown} | undefined;
21+
2022
/**
2123
* Schedules tasks so that they are invoked inside the Zone that is passed in the constructor.
2224
*/
@@ -33,9 +35,13 @@ export class ɵZoneScheduler implements SchedulerLike {
3335
// Wrap the specified work function to make sure that if nested scheduling takes place the
3436
// work is executed in the correct zone
3537
const workInZone = function(this: SchedulerAction<any>, state: any) {
36-
targetZone.runGuarded(() => {
38+
if (targetZone) {
39+
targetZone.runGuarded(() => {
40+
work.apply(this, [state]);
41+
});
42+
} else {
3743
work.apply(this, [state]);
38-
});
44+
}
3945
};
4046

4147
// Scheduling itself needs to be run in zone to ensure setInterval calls for async scheduling are done
@@ -73,11 +79,14 @@ export class ɵAngularFireSchedulers {
7379
constructor(public ngZone: NgZone, public pendingTasks: ExperimentalPendingTasks) {
7480
this.outsideAngular = ngZone.runOutsideAngular(
7581
// @ts-ignore
76-
() => new ɵZoneScheduler(Zone.current)
82+
() => new ɵZoneScheduler(typeof Zone === 'undefined' ? undefined : Zone.current)
7783
);
7884
this.insideAngular = ngZone.run(
7985
// @ts-ignore
80-
() => new ɵZoneScheduler(Zone.current, asyncScheduler)
86+
() => new ɵZoneScheduler(
87+
typeof Zone === 'undefined' ? undefined : Zone.current,
88+
asyncScheduler
89+
)
8190
);
8291
globalThis.ɵAngularFireScheduler ||= this;
8392
}

0 commit comments

Comments
 (0)