Skip to content

Commit b4d8e71

Browse files
fix(reactivity): add back STOP flag (#13605)
1 parent c14171e commit b4d8e71

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/reactivity/src/effect.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export enum EffectFlags {
5252
*/
5353
ALLOW_RECURSE = 1 << 7,
5454
PAUSED = 1 << 8,
55+
STOP = 1 << 10,
5556
}
5657

5758
export class ReactiveEffect<T = any>
@@ -90,7 +91,7 @@ export class ReactiveEffect<T = any>
9091
}
9192

9293
get active(): boolean {
93-
return !!this.flags || this.deps !== undefined
94+
return !(this.flags & EffectFlags.STOP)
9495
}
9596

9697
pause(): void {
@@ -132,6 +133,10 @@ export class ReactiveEffect<T = any>
132133
}
133134

134135
stop(): void {
136+
if (!this.active) {
137+
return
138+
}
139+
this.flags = EffectFlags.STOP
135140
let dep = this.deps
136141
while (dep !== undefined) {
137142
dep = unlink(dep, this)
@@ -140,7 +145,6 @@ export class ReactiveEffect<T = any>
140145
if (sub !== undefined) {
141146
unlink(sub)
142147
}
143-
this.flags = 0
144148
cleanup(this)
145149
}
146150

packages/reactivity/src/effectScope.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class EffectScope implements ReactiveNode {
3333
}
3434

3535
get active(): boolean {
36-
return !!this.flags || this.deps !== undefined
36+
return !(this.flags & EffectFlags.STOP)
3737
}
3838

3939
pause(): void {
@@ -77,6 +77,10 @@ export class EffectScope implements ReactiveNode {
7777
}
7878

7979
stop(): void {
80+
if (!this.active) {
81+
return
82+
}
83+
this.flags = EffectFlags.STOP
8084
let dep = this.deps
8185
while (dep !== undefined) {
8286
const node = dep.dep
@@ -91,7 +95,6 @@ export class EffectScope implements ReactiveNode {
9195
if (sub !== undefined) {
9296
unlink(sub)
9397
}
94-
this.flags = 0
9598
cleanup(this)
9699
}
97100
}

0 commit comments

Comments
 (0)