From: Evan You Date: Wed, 9 Nov 2022 12:50:02 +0000 (+0800) Subject: fix(watch): ensure oldValue in multi-source watcher is always an array X-Git-Tag: v3.2.43~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=23e85e21a50926c48dea4f978e212e4301c20037;p=thirdparty%2Fvuejs%2Fcore.git fix(watch): ensure oldValue in multi-source watcher is always an array fix #7070 --- diff --git a/packages/runtime-core/__tests__/apiWatch.spec.ts b/packages/runtime-core/__tests__/apiWatch.spec.ts index c9db365736..029146b520 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 180843cf74..99445be77d 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 ])