fix(watch): ensure oldValue in multi-source watcher is always an array

fix #7070
This commit is contained in:
Evan You 2022-11-09 20:50:02 +08:00
parent d33292dd47
commit 23e85e21a5
2 changed files with 4 additions and 4 deletions

View 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 }
)

View 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
])