Skip to content

fix(runtime-core): disable deps collection in watch callbacks #2765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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