]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf: reuse currentHydrationNode when possible
authordaiwei <daiwei521@126.com>
Mon, 29 Sep 2025 03:46:24 +0000 (11:46 +0800)
committerdaiwei <daiwei521@126.com>
Mon, 29 Sep 2025 03:46:24 +0000 (11:46 +0800)
packages/runtime-vapor/src/dom/hydration.ts

index f6785f348c3e9a6b2b9b822e18e64504ed7c24e5..2e8cd054a578e25827152d05dcef3c74a2a4e6ed 100644 (file)
@@ -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!,