fix(runtime-core): use correct parentNode when patching dynamicChildren (close #98)

This commit is contained in:
Evan You 2019-10-10 14:49:35 -04:00
parent 58772c62f6
commit 46d875f4e8
2 changed files with 11 additions and 5 deletions

View File

@ -114,7 +114,7 @@ export interface RendererOptions<HostNode = any, HostElement = any> {
createComment(text: string): HostNode createComment(text: string): HostNode
setText(node: HostNode, text: string): void setText(node: HostNode, text: string): void
setElementText(node: HostElement, text: string): void setElementText(node: HostElement, text: string): void
parentNode(node: HostNode): HostNode | null parentNode(node: HostNode): HostElement | null
nextSibling(node: HostNode): HostNode | null nextSibling(node: HostNode): HostNode | null
querySelector(selector: string): HostElement | null querySelector(selector: string): HostElement | null
} }
@ -499,10 +499,11 @@ export function createRenderer<
// children fast path // children fast path
const oldDynamicChildren = n1.dynamicChildren! const oldDynamicChildren = n1.dynamicChildren!
for (let i = 0; i < dynamicChildren.length; i++) { for (let i = 0; i < dynamicChildren.length; i++) {
const oldVNode = oldDynamicChildren[i]
patch( patch(
oldDynamicChildren[i], oldVNode,
dynamicChildren[i], dynamicChildren[i],
el, hostParentNode(oldVNode.el!)!,
null, null,
parentComponent, parentComponent,
parentSuspense, parentSuspense,

View File

@ -4,7 +4,11 @@ const svgNS = 'http://www.w3.org/2000/svg'
export const nodeOps = { export const nodeOps = {
insert: (child: Node, parent: Node, anchor?: Node) => { insert: (child: Node, parent: Node, anchor?: Node) => {
if (anchor != null) { if (anchor != null) {
try {
parent.insertBefore(child, anchor) parent.insertBefore(child, anchor)
} catch (e) {
debugger
}
} else { } else {
parent.appendChild(child) parent.appendChild(child)
} }
@ -32,7 +36,8 @@ export const nodeOps = {
el.textContent = text el.textContent = text
}, },
parentNode: (node: Node): Node | null => node.parentNode, parentNode: (node: Node): HTMLElement | null =>
node.parentNode as HTMLElement,
nextSibling: (node: Node): Node | null => node.nextSibling, nextSibling: (node: Node): Node | null => node.nextSibling,