]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): should pause tracking when initializing legacy options (#2524)
authorHcySunYang <HcySunYang@outlook.com>
Fri, 27 Nov 2020 19:01:01 +0000 (03:01 +0800)
committerGitHub <noreply@github.com>
Fri, 27 Nov 2020 19:01:01 +0000 (14:01 -0500)
fix #2521

packages/runtime-core/__tests__/rendererComponent.spec.ts
packages/runtime-core/src/component.ts

index 5616c22a1b04abe795c1645da55750a7888a4c30..29a7d076d94de7fc5401c6eab60d14e3d6cbf252 100644 (file)
@@ -232,4 +232,47 @@ describe('renderer: component', () => {
     await nextTick()
     expect(serializeInner(root)).toBe(`<div>1</div><div>1</div>`)
   })
+
+  // #2521
+  test('should pause tracking deps when initializing legacy options', async () => {
+    let childInstance = null as any
+    const Child = {
+      props: ['foo'],
+      data() {
+        return {
+          count: 0
+        }
+      },
+      watch: {
+        foo: {
+          immediate: true,
+          handler() {
+            ;(this as any).count
+          }
+        }
+      },
+      created() {
+        childInstance = this as any
+        childInstance.count
+      },
+      render() {
+        return h('h1', (this as any).count)
+      }
+    }
+
+    const App = {
+      setup() {
+        return () => h(Child)
+      },
+      updated: jest.fn()
+    }
+
+    const root = nodeOps.createElement('div')
+    render(h(App), root)
+    expect(App.updated).toHaveBeenCalledTimes(0)
+
+    childInstance.count++
+    await nextTick()
+    expect(App.updated).toHaveBeenCalledTimes(0)
+  })
 })
index 43f700cc2d3ba92127fc1a8ca4cc9dd9722e50e0..9b1fdcef18f12d21502080a6b3e7b7f01fc44286 100644 (file)
@@ -704,7 +704,9 @@ function finishComponentSetup(
   // support for 2.x options
   if (__FEATURE_OPTIONS_API__) {
     currentInstance = instance
+    pauseTracking()
     applyOptions(instance, Component)
+    resetTracking()
     currentInstance = null
   }