Skip to content

Commit b0fad8f

Browse files
committed
test: add test case
1 parent 5164e99 commit b0fad8f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/reactivity/src/effectScope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class EffectScope {
7878
if (this.active) {
7979
let i, l
8080
// #5783
81-
// effects maybe changed when an effect stoped.
81+
// effects will be changed when a watcher stoped.
8282
// so we need to copy it for iteration.
8383
const effectsToStop = this.effects.slice()
8484
for (i = 0, l = effectsToStop.length; i < l; i++) {

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,4 +1118,26 @@ describe('api: watch', () => {
11181118
// own update effect
11191119
expect(instance!.scope.effects.length).toBe(1)
11201120
})
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+
})
11211143
})

0 commit comments

Comments
 (0)