Skip to content

Commit 52e8638

Browse files
committed
disable fragment reactivity during removal (fix vuejs#2100)
1 parent 702b173 commit 52e8638

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

src/compiler/compile.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,15 @@ function directiveComparator (a, b) {
138138
*/
139139

140140
function makeUnlinkFn (vm, dirs, context, contextDirs) {
141-
return function unlink (destroying) {
141+
function unlink (destroying) {
142142
teardownDirs(vm, dirs, destroying)
143143
if (context && contextDirs) {
144144
teardownDirs(context, contextDirs)
145145
}
146146
}
147+
// expose linked directives
148+
unlink.dirs = dirs
149+
return unlink
147150
}
148151

149152
/**

src/fragment/fragment.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy