From 12d5bb5653b5d0c799af68998bb8b33d64b388bc Mon Sep 17 00:00:00 2001 From: daiwei Date: Mon, 29 Sep 2025 11:46:24 +0800 Subject: [PATCH] perf: reuse currentHydrationNode when possible --- packages/runtime-vapor/src/dom/hydration.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/runtime-vapor/src/dom/hydration.ts b/packages/runtime-vapor/src/dom/hydration.ts index f6785f348..2e8cd054a 100644 --- a/packages/runtime-vapor/src/dom/hydration.ts +++ b/packages/runtime-vapor/src/dom/hydration.ts @@ -157,7 +157,11 @@ function locateHydrationNodeImpl(): void { // prepend if (insertionAnchor === 0) { // use prevDynamicCount as logical index to locate the hydration node - node = locateChildByLogicalIndex(insertionParent!, prevDynamicCount)! + node = + prevDynamicCount === 0 && + currentHydrationNode!.parentNode === insertionParent + ? currentHydrationNode + : locateChildByLogicalIndex(insertionParent!, prevDynamicCount)! } // insert else if (insertionAnchor instanceof Node) { @@ -188,7 +192,10 @@ function locateHydrationNodeImpl(): void { node = locateChildByLogicalIndex(insertionParent!, appendIndex + 1)! } else { if (insertionAnchor === null) { - node = locateChildByLogicalIndex(insertionParent!, 0)! + node = + currentHydrationNode!.parentNode === insertionParent + ? currentHydrationNode + : locateChildByLogicalIndex(insertionParent!, 0)! } else { node = locateChildByLogicalIndex( insertionParent!,