Skip to content

Commit 6eb2d11

Browse files
committed
chore: update test
1 parent 894aefd commit 6eb2d11

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

packages/reactivity/__tests__/effectScope.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ describe('reactivity/effect/scope', () => {
176176

177177
expect('[Vue warn] cannot run an inactive effect scope.').toHaveBeenWarned()
178178

179-
expect(scope.effects.length).toBe(1)
179+
expect(scope.effects.length).toBe(0)
180180

181181
counter.num = 7
182182
expect(dummy).toBe(0)
@@ -323,7 +323,7 @@ describe('reactivity/effect/scope', () => {
323323
expect(fnSpy).toHaveBeenCalledTimes(3)
324324
})
325325

326-
test('clean up watchers during effect scope stop', async () => {
326+
test('clean up effects/cleanups during effect scope stop', async () => {
327327
const count = ref(0)
328328
const scope = effectScope()
329329
let watcherCalls = 0

packages/reactivity/src/effectScope.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,20 @@ export class EffectScope {
122122
for (i = 0, l = effects.length; i < l; i++) {
123123
effects[i].stop()
124124
}
125-
const cleanups = this.cleanups.slice()
126-
for (i = 0, l = cleanups.length; i < l; i++) {
127-
cleanups[i]()
125+
this.effects.length = 0
126+
127+
for (i = 0, l = this.cleanups.length; i < l; i++) {
128+
this.cleanups[i]()
128129
}
130+
this.cleanups.length = 0
131+
129132
if (this.scopes) {
130133
for (i = 0, l = this.scopes.length; i < l; i++) {
131134
this.scopes[i].stop(true)
132135
}
136+
this.scopes.length = 0
133137
}
138+
134139
// nested scope, dereference from parent to avoid memory leaks
135140
if (!this.detached && this.parent && !fromParent) {
136141
// optimized O(1) removal

packages/reactivity/src/watch.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from './effect'
2424
import { isReactive, isShallow } from './reactive'
2525
import { type Ref, isRef } from './ref'
26-
import { getCurrentScope, onScopeDispose } from './effectScope'
26+
import { getCurrentScope } from './effectScope'
2727

2828
// These errors were transferred from `packages/runtime-core/src/errorHandling.ts`
2929
// to @vue/reactivity to allow co-location with the moved base watch logic, hence
@@ -215,10 +215,8 @@ export function watch(
215215
effect.stop()
216216
if (scope) {
217217
remove(scope.effects, effect)
218-
remove(scope.cleanups, watchHandle)
219218
}
220219
}
221-
onScopeDispose(watchHandle, true)
222220

223221
if (once && cb) {
224222
const _cb = cb

packages/runtime-core/__tests__/apiWatch.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
} from '@vue/runtime-test'
2626
import {
2727
type DebuggerEvent,
28-
EffectFlags,
2928
ITERATE_KEY,
3029
type Ref,
3130
type ShallowRef,
@@ -1341,7 +1340,7 @@ describe('api: watch', () => {
13411340
await nextTick()
13421341
await nextTick()
13431342

1344-
expect(instance!.scope.effects[0].flags & EffectFlags.ACTIVE).toBeFalsy()
1343+
expect(instance!.scope.effects.length).toBe(0)
13451344
})
13461345

13471346
test('this.$watch should pass `this.proxy` to watch source as the first argument ', () => {

0 commit comments

Comments
 (0)