Skip to content

Commit

Permalink
fix(watch): fix watching multiple sources containing shallowRef (#5381)
Browse files Browse the repository at this point in the history
fix #5371
  • Loading branch information
edison1105 committed May 13, 2022
1 parent 04fff05 commit 220f255
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/runtime-core/__tests__/apiWatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,21 @@ describe('api: watch', () => {
expect(sideEffect).toBe(2)
})

test('should force trigger on triggerRef when watching multiple sources: shallow ref array', async () => {
const v = shallowRef([] as any)
const spy = jest.fn()
watch([v], () => {
spy()
})

v.value.push(1)
triggerRef(v)

await nextTick()
// should trigger now
expect(spy).toHaveBeenCalledTimes(1)
})

// #2125
test('watchEffect should not recursively trigger itself', async () => {
const spy = jest.fn()
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function doWatch(
deep = true
} else if (isArray(source)) {
isMultiSource = true
forceTrigger = source.some(isReactive)
forceTrigger = source.some(s => isReactive(s) || isShallow(s))
getter = () =>
source.map(s => {
if (isRef(s)) {
Expand Down

0 comments on commit 220f255

Please sign in to comment.