@@ -72,17 +72,6 @@ Fragment.prototype.callHook = function (hook) {
7272 }
7373}
7474
75- /**
76- * Destroy the fragment.
77- */
78-
79- Fragment . prototype . destroy = function ( ) {
80- if ( this . parentFrag ) {
81- this . parentFrag . childFrags . $remove ( this )
82- }
83- this . unlink ( )
84- }
85-
8675/**
8776 * Insert fragment before target, single node version
8877 *
@@ -109,7 +98,7 @@ function singleRemove () {
10998 this . inserted = false
11099 var shouldCallRemove = inDoc ( this . node )
111100 var self = this
112- self . callHook ( destroyChild )
101+ this . beforeRemove ( )
113102 removeWithTransition ( this . node , this . vm , function ( ) {
114103 if ( shouldCallRemove ) {
115104 self . callHook ( detach )
@@ -147,7 +136,7 @@ function multiRemove () {
147136 this . inserted = false
148137 var self = this
149138 var shouldCallRemove = inDoc ( this . node )
150- self . callHook ( destroyChild )
139+ this . beforeRemove ( )
151140 removeNodeRange ( this . node , this . end , this . vm , this . frag , function ( ) {
152141 if ( shouldCallRemove ) {
153142 self . callHook ( detach )
@@ -156,6 +145,33 @@ function multiRemove () {
156145 } )
157146}
158147
148+ /**
149+ * Prepare the fragment for removal.
150+ * Most importantly, disable the watchers on all the
151+ * directives so that the rendered content stays the same
152+ * during removal.
153+ */
154+
155+ Fragment . prototype . beforeRemove = function ( ) {
156+ this . callHook ( destroyChild )
157+ var dirs = this . unlink . dirs
158+ var i = dirs . length
159+ while ( i -- ) {
160+ dirs [ i ] . _watcher && dirs [ i ] . _watcher . teardown ( )
161+ }
162+ }
163+
164+ /**
165+ * Destroy the fragment.
166+ */
167+
168+ Fragment . prototype . destroy = function ( ) {
169+ if ( this . parentFrag ) {
170+ this . parentFrag . childFrags . $remove ( this )
171+ }
172+ this . unlink ( )
173+ }
174+
159175/**
160176 * Call attach hook for a Vue instance.
161177 *
0 commit comments