]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(watch): fix deep watchers on refs containing primitives (#984)
authorCarlos Rodrigues <carlos@hypermob.co.uk>
Fri, 17 Apr 2020 13:55:41 +0000 (14:55 +0100)
committerGitHub <noreply@github.com>
Fri, 17 Apr 2020 13:55:41 +0000 (09:55 -0400)
packages/runtime-core/__tests__/apiWatch.spec.ts
packages/runtime-core/src/apiWatch.ts

index f42640abc4d5fc024eeb752db15402fcfeb5d53d..8b58ded39037fc5fe3821346f62205dac043d6e0 100644 (file)
@@ -86,6 +86,23 @@ describe('api: watch', () => {
     expect(dummy).toMatchObject([2, 1])
   })
 
+  it('watching primitive with deep: true', async () => {
+    const count = ref(0)
+    let dummy
+    watch(
+      count,
+      (c, prevCount) => {
+        dummy = [c, prevCount]
+      },
+      {
+        deep: true
+      }
+    )
+    count.value++
+    await nextTick()
+    expect(dummy).toMatchObject([1, 0])
+  })
+
   it('watching multiple sources', async () => {
     const state = reactive({ count: 1 })
     const count = ref(1)
index ff3e7c6257ea4105c774437925fe4c5b9a55652f..1c02c115e939d2de85a61b28b394e771b7f6bf86 100644 (file)
@@ -286,6 +286,9 @@ export function instanceWatch(
 
 function traverse(value: unknown, seen: Set<unknown> = new Set()) {
   if (!isObject(value) || seen.has(value)) {
+    return value
+  }
+  if (seen.has(value)) {
     return
   }
   seen.add(value)