From f4b6be021cc0b2e25e3486ed718168b4ecf7fcf2 Mon Sep 17 00:00:00 2001 From: sam0212 <5402406@qq.com> Date: Fri, 3 Nov 2023 09:05:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(core=20-=20patch)=EF=BC=9Awhen=20before=20p?= =?UTF-8?q?atch:=20old=20keys=20like=20[a,=20b,=20c=20...]=20new=20keys=20?= =?UTF-8?q?like=20[d,=20b,=20b,=20e,=20....],=20when=20patch=20the=20secon?= =?UTF-8?q?d=20key=20"b"=20Vnode=20by=20new=20children,=20the=20vnodeToMov?= =?UTF-8?q?e=20will=20be=20undefined,=20so=20need=20add=20a=20condition=20?= =?UTF-8?q?for=20vnodeToMove?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix an error when diff patch, when before patch: old keys like [a, b, c ...] new keys like [d, b, b, e, ....], when patch the second key "b" Vnode by new children, the vnodeToMove will be undefined, so need add a condition for vnodeToMove --- src/core/vdom/patch.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/vdom/patch.ts b/src/core/vdom/patch.ts index 173840787bc..20767c62d87 100644 --- a/src/core/vdom/patch.ts +++ b/src/core/vdom/patch.ts @@ -510,7 +510,10 @@ export function createPatchFunction(backend) { ) } else { vnodeToMove = oldCh[idxInOld] - if (sameVnode(vnodeToMove, newStartVnode)) { + // when before patch: old keys like [a, b, c ...] new keys like [d, b, b, e, ....] + // when patch the second key "b" Vnode by new children + // the vnodeToMove will be undefined, so need add a condition for vnodeToMove + if (vnodeToMove && sameVnode(vnodeToMove, newStartVnode)) { patchVnode( vnodeToMove, newStartVnode,