Skip to content

Commit d8f0ce9

Browse files
committed
fragment attach hook should check if child is inDoc (fix #2445)
1 parent 55d6292 commit d8f0ce9

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/fragment/fragment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Fragment.prototype.destroy = function () {
192192
*/
193193

194194
function attach (child) {
195-
if (!child._isAttached) {
195+
if (!child._isAttached && inDoc(child.$el)) {
196196
child._callHook('attached')
197197
}
198198
}
@@ -204,7 +204,7 @@ function attach (child) {
204204
*/
205205

206206
function detach (child) {
207-
if (child._isAttached) {
207+
if (child._isAttached && !inDoc(child.$el)) {
208208
child._callHook('detached')
209209
}
210210
}

test/unit/specs/misc_spec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,4 +485,44 @@ describe('Misc', function () {
485485
})
486486
}).not.toThrow()
487487
})
488+
489+
// #2445
490+
it('fragment attach hook should check if child is inDoc', function (done) {
491+
var el = document.createElement('div')
492+
document.body.appendChild(el)
493+
var spyParent = jasmine.createSpy('attached parent')
494+
var spyChild = jasmine.createSpy('attached child')
495+
496+
new Vue({
497+
el: el,
498+
template: '<comp v-for="n in 1"></comp>',
499+
components: {
500+
comp: {
501+
template: '<div><child></child></div>',
502+
attached: function () {
503+
expect(_.inDoc(this.$el)).toBe(true)
504+
spyParent()
505+
},
506+
activate: function (next) {
507+
setTimeout(function () {
508+
next()
509+
check()
510+
}, 100)
511+
},
512+
components: {
513+
child: {
514+
template: 'yo',
515+
attached: spyChild
516+
}
517+
}
518+
}
519+
}
520+
})
521+
522+
function check () {
523+
expect(spyParent).toHaveBeenCalled()
524+
expect(spyChild).toHaveBeenCalled()
525+
done()
526+
}
527+
})
488528
})

0 commit comments

Comments
 (0)