Skip to content

Commit d257f70

Browse files
author
kimozhang
committed
fix: 双端比较在非理想情况时, 获取 idxInOld 需要判断 node 是否为空
1 parent 8116d67 commit d257f70

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

docs/zh/renderer-diff.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
883883
} else {
884884
// 遍历旧 children,试图寻找与 newStartVNode 拥有相同 key 值的元素
885885
const idxInOld = prevChildren.findIndex(
886-
node => node.key === newStartVNode.key
886+
node => node?.key === newStartVNode.key
887887
)
888888
}
889889
}
@@ -908,7 +908,7 @@ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
908908
} else {
909909
// 遍历旧 children,试图寻找与 newStartVNode 拥有相同 key 值的元素
910910
const idxInOld = prevChildren.findIndex(
911-
node => node.key === newStartVNode.key
911+
node => node?.key === newStartVNode.key
912912
)
913913
if (idxInOld >= 0) {
914914
// vnodeToMove 就是在旧 children 中找到的节点,该节点所对应的真实 DOM 应该被移动到最前面
@@ -948,7 +948,7 @@ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
948948
// 省略...
949949
} else {
950950
const idxInOld = prevChildren.findIndex(
951-
node => node.key === newStartVNode.key
951+
node => node?.key === newStartVNode.key
952952
)
953953
if (idxInOld >= 0) {
954954
const vnodeToMove = prevChildren[idxInOld]
@@ -991,7 +991,7 @@ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
991991
// 省略...
992992
} else {
993993
const idxInOld = prevChildren.findIndex(
994-
node => node.key === newStartVNode.key
994+
node => node?.key === newStartVNode.key
995995
)
996996
if (idxInOld >= 0) {
997997
const vnodeToMove = prevChildren[idxInOld]

0 commit comments

Comments
 (0)