Skip to content

Commit 26c9a62

Browse files
committed
fix #610 transclusion + partial throws error in $destroy
1 parent 0df318c commit 26c9a62

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/api/lifecycle.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ exports.$destroy = function (remove, deferCleanup) {
8282
}
8383
}
8484
// teardown all directives. this also tearsdown all
85-
// directive-owned watchers.
86-
i = this._directives.length
87-
while (i--) {
85+
// directive-owned watchers. intentionally check for
86+
// directives array length on every loop since directives
87+
// that manages partial compilation can splice ones out
88+
for (i = 0; i < this._directives.length; i++) {
8889
this._directives[i]._teardown()
8990
}
9091
// teardown all user watchers.

test/unit/specs/api/lifecycle_spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,23 @@ if (_.inBrowser) {
254254
expect(spy.calls.count()).toBe(1)
255255
})
256256

257+
it('safely teardown partial compilation', function () {
258+
var vm = new Vue({
259+
template: '<div v-component="dialog"><div v-partial="hello"></div></div>',
260+
partials: {
261+
hello: 'Hello {{name}}'
262+
},
263+
components: {
264+
dialog: {
265+
template: '<content>'
266+
}
267+
}
268+
}).$mount()
269+
expect(function () {
270+
vm.$destroy()
271+
}).not.toThrow()
272+
})
273+
257274
})
258275

259276
describe('$compile', function () {

0 commit comments

Comments
 (0)