Skip to content

Commit de85527

Browse files
committed
fix(reactivity): ensure watch cleanup on effect stop
1 parent b5ff930 commit de85527

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/reactivity/src/effectScope.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ export class EffectScope {
121121
for (i = 0, l = this.effects.length; i < l; i++) {
122122
this.effects[i].stop()
123123
}
124-
for (i = 0, l = this.cleanups.length; i < l; i++) {
125-
this.cleanups[i]()
124+
const cleanups = this.cleanups.slice()
125+
for (i = 0, l = cleanups.length; i < l; i++) {
126+
cleanups[i]()
126127
}
127128
if (this.scopes) {
128129
for (i = 0, l = this.scopes.length; i < l; i++) {

packages/reactivity/src/watch.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,12 @@ export function watch(
215215
effect.stop()
216216
if (scope) {
217217
remove(scope.effects, effect)
218+
remove(scope.cleanups, watchHandle)
218219
}
219220
}
221+
if (scope) {
222+
scope.cleanups.push(watchHandle)
223+
}
220224

221225
if (once && cb) {
222226
const _cb = cb

0 commit comments

Comments
 (0)