From 21c0dfd221380f8d01694689fd03a4d492d73489 Mon Sep 17 00:00:00 2001 From: luwuer Date: Tue, 8 Dec 2020 21:45:34 +0800 Subject: [PATCH] fix(runtime-core): disable deps collection in watch callbacks (#2728) --- packages/runtime-core/src/apiWatch.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index f0ff31fcfdd..296527b0e99 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -5,7 +5,9 @@ import { Ref, ComputedRef, ReactiveEffectOptions, - isReactive + isReactive, + pauseTracking, + resetTracking } from '@vue/reactivity' import { SchedulerJob, queuePreFlushCb } from './scheduler' import { @@ -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() @@ -259,6 +264,7 @@ function doWatch( oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue, onInvalidate ]) + resetTracking() oldValue = newValue } } else {