Skip to content

Commit 21c0dfd

Browse files
committed
fix(runtime-core): disable deps collection in watch callbacks (#2728)
1 parent d87bc2b commit 21c0dfd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/runtime-core/src/apiWatch.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import {
55
Ref,
66
ComputedRef,
77
ReactiveEffectOptions,
8-
isReactive
8+
isReactive,
9+
pauseTracking,
10+
resetTracking
911
} from '@vue/reactivity'
1012
import { SchedulerJob, queuePreFlushCb } from './scheduler'
1113
import {
@@ -249,6 +251,9 @@ function doWatch(
249251
// watch(source, cb)
250252
const newValue = runner()
251253
if (deep || forceTrigger || hasChanged(newValue, oldValue)) {
254+
// ref #2728
255+
// disable deps collection in watch callbacks
256+
pauseTracking()
252257
// cleanup before running cb again
253258
if (cleanup) {
254259
cleanup()
@@ -259,6 +264,7 @@ function doWatch(
259264
oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
260265
onInvalidate
261266
])
267+
resetTracking()
262268
oldValue = newValue
263269
}
264270
} else {

0 commit comments

Comments
 (0)