diff --git a/packages/reactivity/__tests__/watch.spec.ts b/packages/reactivity/__tests__/watch.spec.ts index c8d48543fb1..b3d18e19f71 100644 --- a/packages/reactivity/__tests__/watch.spec.ts +++ b/packages/reactivity/__tests__/watch.spec.ts @@ -193,4 +193,20 @@ describe('watch', () => { scope.stop() expect(calls).toEqual(['sync 2', 'post 2']) }) + + test('once option should be ignored by simple watch', async () => { + let dummy: any + const source = ref(0) + watch( + () => { + dummy = source.value + }, + null, + { once: true }, + ) + expect(dummy).toBe(0) + + source.value++ + expect(dummy).toBe(1) + }) }) diff --git a/packages/reactivity/src/watch.ts b/packages/reactivity/src/watch.ts index ceda454a568..073bf88b93f 100644 --- a/packages/reactivity/src/watch.ts +++ b/packages/reactivity/src/watch.ts @@ -218,19 +218,11 @@ export function watch( } } - if (once) { - if (cb) { - const _cb = cb - cb = (...args) => { - _cb(...args) - watchHandle() - } - } else { - const _getter = getter - getter = () => { - _getter() - watchHandle() - } + if (once && cb) { + const _cb = cb + cb = (...args) => { + _cb(...args) + watchHandle() } }