diff --git a/packages/reactivity/src/effectScope.ts b/packages/reactivity/src/effectScope.ts index 771c8b18e35..01499c5a78e 100644 --- a/packages/reactivity/src/effectScope.ts +++ b/packages/reactivity/src/effectScope.ts @@ -21,10 +21,6 @@ export class EffectScope { * removal */ private index: number | undefined - /** - * activeEffectScope in context not died should be recorded - */ - private aliveEffectScope: EffectScope | undefined constructor(detached = false) { if (!detached && activeEffectScope) { @@ -38,13 +34,12 @@ export class EffectScope { run(fn: () => T): T | undefined { if (this.active) { + const currentEffectScope = activeEffectScope try { - this.aliveEffectScope = activeEffectScope activeEffectScope = this return fn() } finally { - activeEffectScope = this.aliveEffectScope - delete this.aliveEffectScope + activeEffectScope = currentEffectScope } } else if (__DEV__) { warn(`cannot run an inactive effect scope.`) @@ -52,13 +47,11 @@ export class EffectScope { } on() { - this.aliveEffectScope = activeEffectScope activeEffectScope = this } off() { - activeEffectScope = this.aliveEffectScope - delete this.aliveEffectScope + activeEffectScope = this.parent } stop(fromParent?: boolean) {