File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ export class EffectScope {
78
78
if ( this . active ) {
79
79
let i , l
80
80
// #5783
81
- // effects maybe changed when an effect stoped.
81
+ // effects will be changed when a watcher stoped.
82
82
// so we need to copy it for iteration.
83
83
const effectsToStop = this . effects . slice ( )
84
84
for ( i = 0 , l = effectsToStop . length ; i < l ; i ++ ) {
Original file line number Diff line number Diff line change @@ -1118,4 +1118,26 @@ describe('api: watch', () => {
1118
1118
// own update effect
1119
1119
expect ( instance ! . scope . effects . length ) . toBe ( 1 )
1120
1120
} )
1121
+
1122
+ test ( 'handle nested watcher stop properly' , ( ) => {
1123
+ let instance : ComponentInternalInstance
1124
+ const Comp = {
1125
+ setup ( ) {
1126
+ instance = getCurrentInstance ( ) !
1127
+ watch (
1128
+ ( ) => 1 ,
1129
+ ( val , oldVal , onCleanup ) => {
1130
+ const stop = watch ( ( ) => 2 , ( ) => { } )
1131
+ onCleanup ( stop )
1132
+ } ,
1133
+ { immediate : true }
1134
+ )
1135
+ return ( ) => ''
1136
+ }
1137
+ }
1138
+ const root = nodeOps . createElement ( 'div' )
1139
+ createApp ( Comp ) . mount ( root )
1140
+ expect ( instance ! . scope . effects . length ) . toBe ( 3 )
1141
+ instance ! . scope . stop ( )
1142
+ } )
1121
1143
} )
You can’t perform that action at this time.
0 commit comments