Skip to content

Commit a49279d

Browse files
atscottthePunderWoman
authored andcommitted
fix(core): Ensure effects can be created when Zone is not defined (#49890)
Effects should run in the same zone they were created in. However, if ZoneJS is not used at all, effects should just run (without zone). This is similar to what's done in the elements `ComponentNgElementStrategy`. fixes #49798 PR Close #49890
1 parent 49386de commit a49279d

File tree

1 file changed

+7
-3
lines changed
  • packages/core/src/render3/reactivity

1 file changed

+7
-3
lines changed

packages/core/src/render3/reactivity/effect.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ export type EffectCleanupRegisterFn = (cleanupFn: EffectCleanupFn) => void;
3232
*/
3333
export class EffectManager {
3434
private all = new Set<Watch>();
35-
private queue = new Map<Watch, Zone>();
35+
private queue = new Map<Watch, Zone|null>();
3636

3737
create(
3838
effectFn: (onCleanup: (cleanupFn: EffectCleanupFn) => void) => void,
3939
destroyRef: DestroyRef|null, allowSignalWrites: boolean): EffectRef {
40-
const zone = Zone.current;
40+
const zone = (typeof Zone === 'undefined') ? null : Zone.current;
4141
const watch = new Watch(effectFn, (watch) => {
4242
if (!this.all.has(watch)) {
4343
return;
@@ -74,7 +74,11 @@ export class EffectManager {
7474

7575
for (const [watch, zone] of this.queue) {
7676
this.queue.delete(watch);
77-
zone.run(() => watch.run());
77+
if (zone) {
78+
zone.run(() => watch.run());
79+
} else {
80+
watch.run();
81+
}
7882
}
7983
}
8084

0 commit comments

Comments
 (0)