Skip to content

Commit 23e85e2

Browse files
committedNov 9, 2022
fix(watch): ensure oldValue in multi-source watcher is always an array
fix #7070
1 parent d33292d commit 23e85e2

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed
 

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ describe('api: watch', () => {
183183
let called = false
184184
watch(
185185
[a, b],
186-
(newVal, oldVal) => {
186+
([newA, newB], [oldA, oldB]) => {
187187
called = true
188-
expect(newVal).toMatchObject([undefined, undefined])
189-
expect(oldVal).toBeUndefined()
188+
expect([newA, newB]).toMatchObject([undefined, undefined])
189+
expect([oldA, oldB]).toMatchObject([undefined, undefined])
190190
},
191191
{ immediate: true }
192192
)

‎packages/runtime-core/src/apiWatch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ function doWatch(
335335
// pass undefined as the old value when it's changed for the first time
336336
oldValue === INITIAL_WATCHER_VALUE ||
337337
(isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE)
338-
? undefined
338+
? []
339339
: oldValue,
340340
onCleanup
341341
])

0 commit comments

Comments
 (0)
Please sign in to comment.