fix(runtime-core): set fragment root children should also update dynamicChildren (#944)

fix #943
This commit is contained in:
likui 2020-04-08 21:32:09 +08:00 committed by GitHub
parent bc78de2494
commit a27e9ee9ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -163,6 +163,7 @@ const getChildRoot = (
return [vnode, undefined] return [vnode, undefined]
} }
const rawChildren = vnode.children as VNodeArrayChildren const rawChildren = vnode.children as VNodeArrayChildren
const dynamicChildren = vnode.dynamicChildren as VNodeArrayChildren
const children = rawChildren.filter(child => { const children = rawChildren.filter(child => {
return !(isVNode(child) && child.type === Comment) return !(isVNode(child) && child.type === Comment)
}) })
@ -171,7 +172,13 @@ const getChildRoot = (
} }
const childRoot = children[0] const childRoot = children[0]
const index = rawChildren.indexOf(childRoot) const index = rawChildren.indexOf(childRoot)
const setRoot = (updatedRoot: VNode) => (rawChildren[index] = updatedRoot) const dynamicIndex = dynamicChildren
? dynamicChildren.indexOf(childRoot)
: null
const setRoot = (updatedRoot: VNode) => {
rawChildren[index] = updatedRoot
if (dynamicIndex !== null) dynamicChildren[dynamicIndex] = updatedRoot
}
return [normalizeVNode(childRoot), setRoot] return [normalizeVNode(childRoot), setRoot]
} }