From: Evan You Date: Sat, 7 Sep 2019 15:42:07 +0000 (-0400) Subject: fix: handle prev children is null in patch element X-Git-Tag: v3.0.0-alpha.0~810 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7950980dc332260dff4a85f0c2d5448fa261cf06;p=thirdparty%2Fvuejs%2Fcore.git fix: handle prev children is null in patch element --- diff --git a/packages/runtime-core/src/createRenderer.ts b/packages/runtime-core/src/createRenderer.ts index 614a5ced00..d20466f11b 100644 --- a/packages/runtime-core/src/createRenderer.ts +++ b/packages/runtime-core/src/createRenderer.ts @@ -760,6 +760,7 @@ export function createRenderer< } } + // children has 3 possibilities: text, array or no children. if (shapeFlag & ShapeFlags.TEXT_CHILDREN) { // text children fast path if (prevShapeFlag & ShapeFlags.ARRAY_CHILDREN) { @@ -769,18 +770,8 @@ export function createRenderer< hostSetElementText(container, c2 as string) } } else { - if (prevShapeFlag & ShapeFlags.TEXT_CHILDREN) { - hostSetElementText(container, '') - if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) { - mountChildren( - c2 as HostVNodeChildren, - container, - anchor, - parentComponent, - isSVG - ) - } - } else if (prevShapeFlag & ShapeFlags.ARRAY_CHILDREN) { + if (prevShapeFlag & ShapeFlags.ARRAY_CHILDREN) { + // prev children was array if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) { // two arrays, cannot assume anything, do full diff patchKeyedChildren( @@ -793,9 +784,25 @@ export function createRenderer< optimized ) } else { - // c2 is null in this case + // no new children, just unmount old unmountChildren(c1 as HostVNode[], parentComponent, true) } + } else { + // prev children was text OR null + // new children is array OR null + if (prevShapeFlag & ShapeFlags.TEXT_CHILDREN) { + hostSetElementText(container, '') + } + // mount new if array + if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) { + mountChildren( + c2 as HostVNodeChildren, + container, + anchor, + parentComponent, + isSVG + ) + } } } }