Browse Source

fix #610 transclusion + partial throws error in $destroy

Evan You 11 years ago
parent
commit
26c9a62d74
2 changed files with 21 additions and 3 deletions
  1. 4 3
      src/api/lifecycle.js
  2. 17 0
      test/unit/specs/api/lifecycle_spec.js

+ 4 - 3
src/api/lifecycle.js

@@ -82,9 +82,10 @@ exports.$destroy = function (remove, deferCleanup) {
     }
     }
   }
   }
   // teardown all directives. this also tearsdown all
   // teardown all directives. this also tearsdown all
-  // directive-owned watchers.
-  i = this._directives.length
-  while (i--) {
+  // directive-owned watchers. intentionally check for
+  // directives array length on every loop since directives
+  // that manages partial compilation can splice ones out
+  for (i = 0; i < this._directives.length; i++) {
     this._directives[i]._teardown()
     this._directives[i]._teardown()
   }
   }
   // teardown all user watchers.
   // teardown all user watchers.

+ 17 - 0
test/unit/specs/api/lifecycle_spec.js

@@ -254,6 +254,23 @@ if (_.inBrowser) {
         expect(spy.calls.count()).toBe(1)
         expect(spy.calls.count()).toBe(1)
       })
       })
 
 
+      it('safely teardown partial compilation', function () {
+        var vm = new Vue({
+          template: '<div v-component="dialog"><div v-partial="hello"></div></div>',
+          partials: {
+            hello: 'Hello {{name}}'
+          },
+          components: {
+            dialog: {
+              template: '<content>'
+            }
+          }
+        }).$mount()
+        expect(function () {
+          vm.$destroy()
+        }).not.toThrow()
+      })
+
     })
     })
 
 
     describe('$compile', function () {
     describe('$compile', function () {