]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(watch): fix watching multiple sources containing shallowRef (#5381)
authoredison <daiwei521@126.com>
Fri, 13 May 2022 00:20:04 +0000 (08:20 +0800)
committerGitHub <noreply@github.com>
Fri, 13 May 2022 00:20:04 +0000 (20:20 -0400)
fix #5371

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

index 1c6fb0a88df8321a188eca64f87378d09169ca7c..118c5732681be08e2d47f8337ff2f3b43234a072 100644 (file)
@@ -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()
index 84937eeae638fdea997bee9ce1f9a76b8a8e0384..a1922f0cd2ed24cac5177e5f7de499d22e543e28 100644 (file)
@@ -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)) {