]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity): add back STOP flag (#13605)
authorJohnson Chu <johnsoncodehk@gmail.com>
Thu, 10 Jul 2025 09:14:59 +0000 (17:14 +0800)
committerGitHub <noreply@github.com>
Thu, 10 Jul 2025 09:14:59 +0000 (17:14 +0800)
packages/reactivity/src/effect.ts
packages/reactivity/src/effectScope.ts

index af8ebea89a128e6d135b273fd17af0b72aba3ccd..d48900f18ccfb04f63a17922ae0d7bf61d7b2e65 100644 (file)
@@ -52,6 +52,7 @@ export enum EffectFlags {
    */
   ALLOW_RECURSE = 1 << 7,
   PAUSED = 1 << 8,
+  STOP = 1 << 10,
 }
 
 export class ReactiveEffect<T = any>
@@ -90,7 +91,7 @@ export class ReactiveEffect<T = any>
   }
 
   get active(): boolean {
-    return !!this.flags || this.deps !== undefined
+    return !(this.flags & EffectFlags.STOP)
   }
 
   pause(): void {
@@ -132,6 +133,10 @@ export class ReactiveEffect<T = any>
   }
 
   stop(): void {
+    if (!this.active) {
+      return
+    }
+    this.flags = EffectFlags.STOP
     let dep = this.deps
     while (dep !== undefined) {
       dep = unlink(dep, this)
@@ -140,7 +145,6 @@ export class ReactiveEffect<T = any>
     if (sub !== undefined) {
       unlink(sub)
     }
-    this.flags = 0
     cleanup(this)
   }
 
index 819eb1ef73b4ebf76366dda012805e298316c5f2..9d8dd546e10a3a3ad8f16115e7c1098e48795b57 100644 (file)
@@ -33,7 +33,7 @@ export class EffectScope implements ReactiveNode {
   }
 
   get active(): boolean {
-    return !!this.flags || this.deps !== undefined
+    return !(this.flags & EffectFlags.STOP)
   }
 
   pause(): void {
@@ -77,6 +77,10 @@ export class EffectScope implements ReactiveNode {
   }
 
   stop(): void {
+    if (!this.active) {
+      return
+    }
+    this.flags = EffectFlags.STOP
     let dep = this.deps
     while (dep !== undefined) {
       const node = dep.dep
@@ -91,7 +95,6 @@ export class EffectScope implements ReactiveNode {
     if (sub !== undefined) {
       unlink(sub)
     }
-    this.flags = 0
     cleanup(this)
   }
 }