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 () {
192192 */
193193
194194function 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
206206function detach ( child ) {
207- if ( child . _isAttached ) {
207+ if ( child . _isAttached && ! inDoc ( child . $el ) ) {
208208 child . _callHook ( 'detached' )
209209 }
210210}
Original file line number Diff line number Diff 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} )
You can’t perform that action at this time.
0 commit comments