Skip to content
Permalink
Browse files
fix(watch): for immediate watch with single source, ensure cb is call…
…ed with undefined as oldValue (#7075)

fix: #7074
  • Loading branch information
LinusBorg committed Nov 9, 2022
1 parent 9a816dc commit 5dc593ba2833e98eab12bd6c73765805b172185a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
@@ -745,7 +745,7 @@ describe('api: watch', () => {
const state = ref()
const spy = jest.fn()
watch(() => state.value, spy, { immediate: true })
expect(spy).toHaveBeenCalled()
expect(spy).toHaveBeenCalledWith(undefined, undefined, expect.any(Function))
state.value = 3
await nextTick()
expect(spy).toHaveBeenCalledTimes(2)
@@ -333,10 +333,11 @@ function doWatch(
callWithAsyncErrorHandling(cb, instance, ErrorCodes.WATCH_CALLBACK, [
newValue,
// pass undefined as the old value when it's changed for the first time
oldValue === INITIAL_WATCHER_VALUE ||
(isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE)
? []
: oldValue,
oldValue === INITIAL_WATCHER_VALUE
? undefined
: (isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE)
? []
: oldValue,
onCleanup
])
oldValue = newValue

0 comments on commit 5dc593b

Please sign in to comment.