fix(watch): avoid pre watcher firing on unmount

fix #12703
This commit is contained in:
Evan You 2022-08-15 19:06:38 +08:00
parent bd89ce53a9
commit f0057b101e
2 changed files with 3 additions and 6 deletions

View File

@ -274,10 +274,7 @@ function doWatch(
let oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE
// overwrite default run
watcher.run = () => {
if (
!watcher.active &&
!(flush === 'pre' && instance && instance._isBeingDestroyed)
) {
if (!watcher.active) {
return
}
if (cb) {

View File

@ -542,7 +542,7 @@ describe('api: watch', () => {
expect(cb).not.toHaveBeenCalled()
})
it('should fire on component unmount w/ flush: pre', async () => {
it('should not fire on component unmount w/ flush: pre', async () => {
const toggle = ref(true)
const cb = vi.fn()
const Comp = {
@ -560,7 +560,7 @@ describe('api: watch', () => {
expect(cb).not.toHaveBeenCalled()
toggle.value = false
await nextTick()
expect(cb).toHaveBeenCalledTimes(1)
expect(cb).not.toHaveBeenCalled()
})
// vuejs/core#1763