watchEffect 的 onCleanUp 在 sync 模式下没有被调用
ivan-94 opened this issue · comments
ivan commented
复现代码:
const count = ref(0)
watchEffect((onCleanup) => {
const value = unref(count)
console.log(value)
onCleanup(() => {
console.log('clean', value)
})
}, {flush: 'sync'})
count.value++ // 期望 onCleanup 被同步执行
行为和 Vue 不一致
ivan commented
原因是 Watcher 在 update 时,如果是 sync, 就会跳过 queueWatcher:
update() {
/* istanbul ignore else */
if (this.lazy) {
this.dirty = true
} else if (this.sync) {
this.run()
} else {
queueWatcher(this)
}
}
github-actions commented
Stale issue message