Skip to content

Commit

Permalink
fix(fragment): perform direct remove when removing fragments
Browse files Browse the repository at this point in the history
This avoids trying to grab .el from hoisted child nodes (which can
be created by another instance), and also skips transition check
since fragment children cannot have transitions.
  • Loading branch information
yyx990803 committed Dec 22, 2019
1 parent 47a6a84 commit 2fdb499
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1573,10 +1573,14 @@ export function createRenderer<
}

function remove(vnode: HostVNode) {
const { type, el, anchor, children, transition } = vnode
const { type, el, anchor, transition } = vnode
if (type === Fragment) {
removeFragment(el!, anchor!)
return
}

const performRemove = () => {
hostRemove(el!)
if (anchor != null) hostRemove(anchor)
if (
transition != null &&
!transition.persisted &&
Expand All @@ -1585,11 +1589,7 @@ export function createRenderer<
transition.afterLeave()
}
}
if (type === Fragment) {
performRemove()
removeChildren(children as HostVNode[])
return
}

if (
vnode.shapeFlag & ShapeFlags.ELEMENT &&
transition != null &&
Expand All @@ -1607,10 +1607,16 @@ export function createRenderer<
}
}

function removeChildren(children: HostVNode[]) {
for (let i = 0; i < children.length; i++) {
remove(children[i])
function removeFragment(cur: HostNode, end: HostNode) {
// For fragments, directly remove all contained DOM nodes.
// (fragment child nodes cannot have transition)
let next
while (cur !== end) {
next = hostNextSibling(cur)!
hostRemove(cur)
cur = next
}
hostRemove(end)
}

function unmountComponent(
Expand Down

0 comments on commit 2fdb499

Please sign in to comment.