]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(watch): for immediate watch with single source, ensure cb is called with undefine...
authorThorsten Lünborg <t.luenborg@googlemail.com>
Wed, 9 Nov 2022 23:19:35 +0000 (00:19 +0100)
committerGitHub <noreply@github.com>
Wed, 9 Nov 2022 23:19:35 +0000 (18:19 -0500)
fix: #7074

packages/runtime-core/__tests__/apiWatch.spec.ts
packages/runtime-core/src/apiWatch.ts

index 029146b52057c7856f3d7b57aa51015e20acf719..f6bad14ddb9b8621b5720a03095e2d1904d9a182 100644 (file)
@@ -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)
index 99445be77d2d5c0337b9ef187b69f6dd572d8865..4999e11f0c94820d5e5ca2f1907d6f49840d42ed 100644 (file)
@@ -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