From 23e85e21a50926c48dea4f978e212e4301c20037 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 9 Nov 2022 20:50:02 +0800 Subject: [PATCH] fix(watch): ensure oldValue in multi-source watcher is always an array fix #7070 --- packages/runtime-core/__tests__/apiWatch.spec.ts | 6 +++--- packages/runtime-core/src/apiWatch.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/runtime-core/__tests__/apiWatch.spec.ts b/packages/runtime-core/__tests__/apiWatch.spec.ts index c9db3657367..029146b5205 100644 --- a/packages/runtime-core/__tests__/apiWatch.spec.ts +++ b/packages/runtime-core/__tests__/apiWatch.spec.ts @@ -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 } ) diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 180843cf745..99445be77d2 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -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 ])