File tree Expand file tree Collapse file tree 4 files changed +12
-10
lines changed Expand file tree Collapse file tree 4 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -176,7 +176,7 @@ describe('reactivity/effect/scope', () => {
176
176
177
177
expect ( '[Vue warn] cannot run an inactive effect scope.' ) . toHaveBeenWarned ( )
178
178
179
- expect ( scope . effects . length ) . toBe ( 1 )
179
+ expect ( scope . effects . length ) . toBe ( 0 )
180
180
181
181
counter . num = 7
182
182
expect ( dummy ) . toBe ( 0 )
@@ -323,7 +323,7 @@ describe('reactivity/effect/scope', () => {
323
323
expect ( fnSpy ) . toHaveBeenCalledTimes ( 3 )
324
324
} )
325
325
326
- test ( 'clean up watchers during effect scope stop' , async ( ) => {
326
+ test ( 'clean up effects/cleanups during effect scope stop' , async ( ) => {
327
327
const count = ref ( 0 )
328
328
const scope = effectScope ( )
329
329
let watcherCalls = 0
Original file line number Diff line number Diff line change @@ -122,15 +122,20 @@ export class EffectScope {
122
122
for ( i = 0 , l = effects . length ; i < l ; i ++ ) {
123
123
effects [ i ] . stop ( )
124
124
}
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 ] ( )
128
129
}
130
+ this . cleanups . length = 0
131
+
129
132
if ( this . scopes ) {
130
133
for ( i = 0 , l = this . scopes . length ; i < l ; i ++ ) {
131
134
this . scopes [ i ] . stop ( true )
132
135
}
136
+ this . scopes . length = 0
133
137
}
138
+
134
139
// nested scope, dereference from parent to avoid memory leaks
135
140
if ( ! this . detached && this . parent && ! fromParent ) {
136
141
// optimized O(1) removal
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ import {
23
23
} from './effect'
24
24
import { isReactive , isShallow } from './reactive'
25
25
import { type Ref , isRef } from './ref'
26
- import { getCurrentScope , onScopeDispose } from './effectScope'
26
+ import { getCurrentScope } from './effectScope'
27
27
28
28
// These errors were transferred from `packages/runtime-core/src/errorHandling.ts`
29
29
// to @vue /reactivity to allow co-location with the moved base watch logic, hence
@@ -215,10 +215,8 @@ export function watch(
215
215
effect . stop ( )
216
216
if ( scope ) {
217
217
remove ( scope . effects , effect )
218
- remove ( scope . cleanups , watchHandle )
219
218
}
220
219
}
221
- onScopeDispose ( watchHandle , true )
222
220
223
221
if ( once && cb ) {
224
222
const _cb = cb
Original file line number Diff line number Diff line change @@ -25,7 +25,6 @@ import {
25
25
} from '@vue/runtime-test'
26
26
import {
27
27
type DebuggerEvent ,
28
- EffectFlags ,
29
28
ITERATE_KEY ,
30
29
type Ref ,
31
30
type ShallowRef ,
@@ -1341,7 +1340,7 @@ describe('api: watch', () => {
1341
1340
await nextTick ( )
1342
1341
await nextTick ( )
1343
1342
1344
- expect ( instance ! . scope . effects [ 0 ] . flags & EffectFlags . ACTIVE ) . toBeFalsy ( )
1343
+ expect ( instance ! . scope . effects . length ) . toBe ( 0 )
1345
1344
} )
1346
1345
1347
1346
test ( 'this.$watch should pass `this.proxy` to watch source as the first argument ' , ( ) => {
You can’t perform that action at this time.
0 commit comments