From f567f59fe70a77cda3215ba9db5878579cbdf0ab Mon Sep 17 00:00:00 2001 From: daiwei Date: Mon, 29 Sep 2025 22:10:24 +0800 Subject: [PATCH] perf: replace $lastLogicalChild with vfor end anchor --- packages/runtime-vapor/src/apiCreateFor.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/runtime-vapor/src/apiCreateFor.ts b/packages/runtime-vapor/src/apiCreateFor.ts index 51b563d97..a6db691f7 100644 --- a/packages/runtime-vapor/src/apiCreateFor.ts +++ b/packages/runtime-vapor/src/apiCreateFor.ts @@ -35,6 +35,7 @@ import { } from './dom/hydration' import { ForFragment, VaporFragment, findLastChild } from './fragment' import { + type ChildItem, insertionAnchor, insertionParent, resetInsertionState, @@ -150,6 +151,15 @@ export const createFor = ( if (!parentAnchor || (parentAnchor && !isComment(parentAnchor, ']'))) { throw new Error(`v-for fragment anchor node was not found.`) } + + // $lastLogicalChild is the fragment start anchor; replacing it with end anchor + // can avoid the call to locateEndAnchor within locateChildByLogicalIndex + if (_insertionParent && _insertionParent!.$lastLogicalChild) { + ;(parentAnchor as any as ChildItem).$idx = ( + _insertionParent!.$lastLogicalChild as ChildItem + ).$idx + _insertionParent.$lastLogicalChild = parentAnchor + } } } else { parent = parent || parentAnchor!.parentNode