File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -192,7 +192,7 @@ Fragment.prototype.destroy = function () {
192
192
*/
193
193
194
194
function attach ( child ) {
195
- if ( ! child . _isAttached ) {
195
+ if ( ! child . _isAttached && inDoc ( child . $el ) ) {
196
196
child . _callHook ( 'attached' )
197
197
}
198
198
}
@@ -204,7 +204,7 @@ function attach (child) {
204
204
*/
205
205
206
206
function detach ( child ) {
207
- if ( child . _isAttached ) {
207
+ if ( child . _isAttached && ! inDoc ( child . $el ) ) {
208
208
child . _callHook ( 'detached' )
209
209
}
210
210
}
Original file line number Diff line number Diff line change @@ -485,4 +485,44 @@ describe('Misc', function () {
485
485
} )
486
486
} ) . not . toThrow ( )
487
487
} )
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
+ } )
488
528
} )
You can’t perform that action at this time.
0 commit comments