Skip to content

Commit 7516baf

Browse files
committed
fix(transition): check existence of el.parentNode, fix vuejs#8199
If the new parentNode gets a `textContent` or `innerHTML` property during patching, the `transition` node would have been detached early, which means `el.parentNode` no longer exists.
1 parent 52719cc commit 7516baf

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/platforms/web/runtime/modules/transition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export function leave (vnode: VNodeWithData, rm: Function) {
251251
return
252252
}
253253
// record leaving element
254-
if (!vnode.data.show) {
254+
if (!vnode.data.show && el.parentNode) {
255255
(el.parentNode._pending || (el.parentNode._pending = {}))[(vnode.key: any)] = vnode
256256
}
257257
beforeLeave && beforeLeave(el)

test/unit/features/transition/transition.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,5 +1167,27 @@ if (!isIE9) {
11671167
expect(vm.$el.innerHTML).toBe('<!---->')
11681168
}).then(done)
11691169
})
1170+
1171+
// #8199
1172+
it('should not throw error when replaced by v-html contents', (done) => {
1173+
const vm = new Vue({
1174+
template: `
1175+
<div>
1176+
<div v-if="ok" :class="ok">
1177+
<transition>
1178+
<span>a</span>
1179+
</transition>
1180+
</div>
1181+
<div v-else v-html="ok"></div>
1182+
</div>
1183+
`,
1184+
data: { ok: true }
1185+
}).$mount(el)
1186+
1187+
vm.ok = false
1188+
waitForUpdate(() => {
1189+
expect(vm.$el.children[0].innerHTML).toBe('false')
1190+
}).then(done)
1191+
})
11701192
})
11711193
}

0 commit comments

Comments
 (0)