Skip to content

Commit

Permalink
fix(watch): ensure oldValue in multi-source watcher is always an array
Browse files Browse the repository at this point in the history
fix #7070
  • Loading branch information
yyx990803 committed Nov 9, 2022
1 parent d33292d commit 23e85e2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/runtime-core/__tests__/apiWatch.spec.ts
Expand Up @@ -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 }
)
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/apiWatch.ts
Expand Up @@ -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
])
Expand Down

0 comments on commit 23e85e2

Please sign in to comment.