]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(watch): ensure oldValue in multi-source watcher is always an array
authorEvan You <yyx990803@gmail.com>
Wed, 9 Nov 2022 12:50:02 +0000 (20:50 +0800)
committerEvan You <yyx990803@gmail.com>
Wed, 9 Nov 2022 12:50:02 +0000 (20:50 +0800)
fix #7070

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

index c9db3657367beac6816d07d8a24d3ae8a719f774..029146b52057c7856f3d7b57aa51015e20acf719 100644 (file)
@@ -183,10 +183,10 @@ describe('api: watch', () => {
     let called = false
     watch(
       [a, b],
-      (newVal, oldVal) => {
+      ([newA, newB], [oldA, oldB]) => {
         called = true
-        expect(newVal).toMatchObject([undefined, undefined])
-        expect(oldVal).toBeUndefined()
+        expect([newA, newB]).toMatchObject([undefined, undefined])
+        expect([oldA, oldB]).toMatchObject([undefined, undefined])
       },
       { immediate: true }
     )
index 180843cf745596916b0f37faaf243a7b6a3e8790..99445be77d2d5c0337b9ef187b69f6dd572d8865 100644 (file)
@@ -335,7 +335,7 @@ function doWatch(
           // pass undefined as the old value when it's changed for the first time
           oldValue === INITIAL_WATCHER_VALUE ||
           (isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE)
-            ? undefined
+            ? []
             : oldValue,
           onCleanup
         ])