Skip to content

Commit

Permalink
fix(watch): avoid pre watcher firing on unmount
Browse files Browse the repository at this point in the history
fix #12703
  • Loading branch information
yyx990803 committed Aug 15, 2022
1 parent bd89ce5 commit f0057b1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/v3/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/features/v3/apiWatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
Expand Down

0 comments on commit f0057b1

Please sign in to comment.