Skip to content

Commit 7df204e

Browse files
committed
v-show: skip transition if element is detached (fix #1717)
1 parent d40b51b commit 7df204e

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

src/directives/internal/transition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var Transition = require('../../transition/transition')
33

44
module.exports = {
55

6-
priority: 1000,
6+
priority: 1100,
77

88
update: function (id, oldId) {
99
var el = this.el

src/directives/public/show.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@ module.exports = {
1212
},
1313

1414
update: function (value) {
15-
var el = this.el
16-
transition.apply(el, value ? 1 : -1, function () {
15+
this.apply(this.el, value)
16+
if (this.elseEl) {
17+
this.apply(this.elseEl, !value)
18+
}
19+
},
20+
21+
apply: function (el, value) {
22+
function done () {
1723
el.style.display = value ? '' : 'none'
18-
}, this.vm)
19-
var elseEl = this.elseEl
20-
if (elseEl) {
21-
transition.apply(elseEl, value ? -1 : 1, function () {
22-
elseEl.style.display = value ? 'none' : ''
23-
}, this.vm)
24+
}
25+
// do not apply transition if not in doc
26+
if (_.inDoc(el)) {
27+
transition.apply(el, value ? 1 : -1, done, this.vm)
28+
} else {
29+
done()
2430
}
2531
}
2632
}

test/unit/specs/directives/public/show_spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ if (_.inBrowser) {
99
var el
1010
beforeEach(function () {
1111
el = document.createElement('div')
12+
document.body.appendChild(el)
1213
spyOn(transition, 'apply').and.callThrough()
1314
})
1415

16+
afterEach(function () {
17+
document.body.removeChild(el)
18+
})
19+
1520
it('should work', function () {
1621
var dir = {
1722
el: el,
1823
update: def.update,
24+
apply: def.apply,
1925
vm: new Vue()
2026
}
2127
dir.update(false)

0 commit comments

Comments
 (0)