fix: handle prev children is null in patch element
This commit is contained in:
parent
3904678306
commit
7950980dc3
@ -760,6 +760,7 @@ export function createRenderer<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// children has 3 possibilities: text, array or no children.
|
||||||
if (shapeFlag & ShapeFlags.TEXT_CHILDREN) {
|
if (shapeFlag & ShapeFlags.TEXT_CHILDREN) {
|
||||||
// text children fast path
|
// text children fast path
|
||||||
if (prevShapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
if (prevShapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
||||||
@ -769,18 +770,8 @@ export function createRenderer<
|
|||||||
hostSetElementText(container, c2 as string)
|
hostSetElementText(container, c2 as string)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (prevShapeFlag & ShapeFlags.TEXT_CHILDREN) {
|
if (prevShapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
||||||
hostSetElementText(container, '')
|
// prev children was array
|
||||||
if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
|
||||||
mountChildren(
|
|
||||||
c2 as HostVNodeChildren,
|
|
||||||
container,
|
|
||||||
anchor,
|
|
||||||
parentComponent,
|
|
||||||
isSVG
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else if (prevShapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
|
||||||
if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
||||||
// two arrays, cannot assume anything, do full diff
|
// two arrays, cannot assume anything, do full diff
|
||||||
patchKeyedChildren(
|
patchKeyedChildren(
|
||||||
@ -793,9 +784,25 @@ export function createRenderer<
|
|||||||
optimized
|
optimized
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// c2 is null in this case
|
// no new children, just unmount old
|
||||||
unmountChildren(c1 as HostVNode[], parentComponent, true)
|
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
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user