Skip to content

Commit

Permalink
fix(runtime-core): disable deps collection in watch callbacks (vuejs#…
Browse files Browse the repository at this point in the history
  • Loading branch information
luwuer committed Feb 26, 2021
1 parent d87bc2b commit 21c0dfd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/runtime-core/src/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
Ref,
ComputedRef,
ReactiveEffectOptions,
isReactive
isReactive,
pauseTracking,
resetTracking
} from '@vue/reactivity'
import { SchedulerJob, queuePreFlushCb } from './scheduler'
import {
Expand Down Expand Up @@ -249,6 +251,9 @@ function doWatch(
// watch(source, cb)
const newValue = runner()
if (deep || forceTrigger || hasChanged(newValue, oldValue)) {
// ref #2728
// disable deps collection in watch callbacks
pauseTracking()
// cleanup before running cb again
if (cleanup) {
cleanup()
Expand All @@ -259,6 +264,7 @@ function doWatch(
oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
onInvalidate
])
resetTracking()
oldValue = newValue
}
} else {
Expand Down

0 comments on commit 21c0dfd

Please sign in to comment.