Преглед изворни кода

fix unnecessary child watcher calls on parent re-render (fix #3453)

Evan You пре 9 година
родитељ
комит
e08d6b9193
2 измењених фајлова са 24 додато и 5 уклоњено
  1. 0 5
      src/core/instance/lifecycle.js
  2. 24 0
      test/unit/features/options/props.spec.js

+ 0 - 5
src/core/instance/lifecycle.js

@@ -151,11 +151,6 @@ export function lifecycleMixin (Vue: Class<Component>) {
     if (vm._watcher) {
       vm._watcher.update()
     }
-    if (vm._watchers.length) {
-      for (let i = 0; i < vm._watchers.length; i++) {
-        vm._watchers[i].update(true /* shallow */)
-      }
-    }
   }
 
   Vue.prototype.$destroy = function () {

+ 24 - 0
test/unit/features/options/props.spec.js

@@ -349,4 +349,28 @@ describe('Options props', () => {
     }).$mount()
     expect(console.error.calls.count()).toBe(0)
   })
+
+  // #3453
+  it('should not fire watcher on object/array props when parent re-renders', done => {
+    const spy = jasmine.createSpy()
+    const vm = new Vue({
+      data: {
+        arr: []
+      },
+      template: '<test :prop="arr">hi</test>',
+      components: {
+        test: {
+          props: ['prop'],
+          watch: {
+            prop: spy
+          },
+          template: '<div><slot></slot></div>'
+        }
+      }
+    }).$mount()
+    vm.$forceUpdate()
+    waitForUpdate(() => {
+      expect(spy).not.toHaveBeenCalled()
+    }).then(done)
+  })
 })