fix(teleport): proper children traversal when teleport is block root

fix #2324
This commit is contained in:
Evan You
2020-10-10 15:40:31 -04:00
parent 9bb14149b0
commit 2ae3b26679
2 changed files with 39 additions and 44 deletions

View File

@@ -5,7 +5,8 @@ import {
MoveType,
RendererElement,
RendererNode,
RendererOptions
RendererOptions,
traverseStaticChildren
} from '../renderer'
import { VNode, VNodeArrayChildren, VNodeProps } from '../vnode'
import { isString, ShapeFlags } from '@vue/shared'
@@ -142,16 +143,7 @@ export const TeleportImpl = {
// even in block tree mode we need to make sure all root-level nodes
// in the teleport inherit previous DOM references so that they can
// be moved in future patches.
if (n2.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
const oldChildren = n1.children as VNode[]
const children = n2.children as VNode[]
for (let i = 0; i < children.length; i++) {
// only inherit for non-patched nodes (i.e. static ones)
if (!children[i].el) {
children[i].el = oldChildren[i].el
}
}
}
traverseStaticChildren(n1, n2, true)
} else if (!optimized) {
patchChildren(
n1,