Skip to content

Commit 22fbffc

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

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/zones.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ export class ɵZoneScheduler implements SchedulerLike {
3333
// Wrap the specified work function to make sure that if nested scheduling takes place the
3434
// work is executed in the correct zone
3535
const workInZone = function(this: SchedulerAction<any>, state: any) {
36-
targetZone.runGuarded(() => {
36+
if (targetZone) {
37+
targetZone.runGuarded(() => {
38+
work.apply(this, [state]);
39+
});
40+
} else {
3741
work.apply(this, [state]);
38-
});
42+
}
3943
};
4044

4145
// Scheduling itself needs to be run in zone to ensure setInterval calls for async scheduling are done
@@ -73,11 +77,14 @@ export class ɵAngularFireSchedulers {
7377
constructor(public ngZone: NgZone, public pendingTasks: ExperimentalPendingTasks) {
7478
this.outsideAngular = ngZone.runOutsideAngular(
7579
// @ts-ignore
76-
() => new ɵZoneScheduler(Zone.current)
80+
() => new ɵZoneScheduler(typeof Zone === 'undefined' ? undefined : Zone.current)
7781
);
7882
this.insideAngular = ngZone.run(
7983
// @ts-ignore
80-
() => new ɵZoneScheduler(Zone.current, asyncScheduler)
84+
() => new ɵZoneScheduler(
85+
typeof Zone === 'undefined' ? undefined : Zone.current,
86+
asyncScheduler
87+
)
8188
);
8289
globalThis.ɵAngularFireScheduler ||= this;
8390
}

0 commit comments

Comments
 (0)