diff --git a/packages/reactivity/src/baseWatch.ts b/packages/reactivity/src/baseWatch.ts index 2b1c64dd2..b14c0d28d 100644 --- a/packages/reactivity/src/baseWatch.ts +++ b/packages/reactivity/src/baseWatch.ts @@ -123,7 +123,7 @@ export function baseWatch( onTrack, onTrigger, }: BaseWatchOptions = EMPTY_OBJ, -): ReactiveEffect | undefined { +): ReactiveEffect { const warnInvalidSource = (s: unknown) => { onWarn( `Invalid watch source: `, diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 4a34eec0b..106d9cc78 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -224,17 +224,14 @@ function doWatch( handleErrorWithInstance(err, instance, type) extendOptions.scheduler = getScheduler(flush)(instance) - let effect = baseWatch(source, cb, extend({}, options, extendOptions)) - + const effect = baseWatch(source, cb, extend({}, options, extendOptions)) const scope = getCurrentScope() - const unwatch = !effect - ? NOOP - : () => { - effect!.stop() - if (scope) { - remove(scope.effects, effect) - } - } + const unwatch = () => { + effect!.stop() + if (scope) { + remove(scope.effects, effect) + } + } if (__SSR__ && ssrCleanup) ssrCleanup.push(unwatch) return unwatch diff --git a/packages/runtime-vapor/src/apiWatch.ts b/packages/runtime-vapor/src/apiWatch.ts index 2c7cd8f63..9cc0f8e67 100644 --- a/packages/runtime-vapor/src/apiWatch.ts +++ b/packages/runtime-vapor/src/apiWatch.ts @@ -7,7 +7,7 @@ import { baseWatch, getCurrentScope, } from '@vue/reactivity' -import { EMPTY_OBJ, NOOP, extend, isFunction, remove } from '@vue/shared' +import { EMPTY_OBJ, extend, isFunction, remove } from '@vue/shared' import { currentInstance } from './component' import { type SchedulerFactory, @@ -159,14 +159,6 @@ function doWatch( ): WatchStopHandle { const { immediate, deep, flush, once } = options - // TODO remove in 3.5 - if (__DEV__ && deep !== void 0 && typeof deep === 'number') { - warn( - `watch() "deep" option with number value will be used as watch depth in future versions. ` + - `Please use a boolean instead to avoid potential breakage.`, - ) - } - if (__DEV__ && !cb) { if (immediate !== undefined) { warn( @@ -213,17 +205,14 @@ function doWatch( handleErrorWithInstance(err, instance, type) extendOptions.scheduler = getScheduler(flush)(instance) - let effect = baseWatch(source, cb, extend({}, options, extendOptions)) - + const effect = baseWatch(source, cb, extend({}, options, extendOptions)) const scope = getCurrentScope() - const unwatch = !effect - ? NOOP - : () => { - effect!.stop() - if (scope) { - remove(scope.effects, effect) - } - } + const unwatch = () => { + effect!.stop() + if (scope) { + remove(scope.effects, effect) + } + } if (__SSR__ && ssrCleanup) ssrCleanup.push(unwatch) return unwatch