]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf: don't initialize hydration state if no anchor
authordaiwei <daiwei521@126.com>
Tue, 16 Sep 2025 07:01:29 +0000 (15:01 +0800)
committerdaiwei <daiwei521@126.com>
Wed, 17 Sep 2025 02:09:29 +0000 (10:09 +0800)
packages/runtime-vapor/src/insertionState.ts

index 0b29f59d2025a758695c8156305e616fd4d0eed5..3a28ac08a5b9e39e17b768312656b32c0765b67f 100644 (file)
@@ -30,18 +30,23 @@ export function setInsertionState(
   anchor?: Node | 0 | null | number,
 ): void {
   insertionParent = parent
-  if (isHydrating) {
-    initializeHydrationState(anchor, parent)
+
+  if (anchor !== undefined) {
+    if (isHydrating) {
+      insertionAnchor = anchor as Node
+      initializeHydrationState(parent)
+    } else {
+      // special handling append anchor value to null
+      insertionAnchor =
+        typeof anchor === 'number' && anchor > 0 ? null : (anchor as Node)
+      cacheTemplateChildren(parent)
+    }
   } else {
-    cacheTemplateChildren(anchor, parent)
+    insertionAnchor = undefined
   }
 }
 
-function initializeHydrationState(
-  anchor: number | Node | null | undefined,
-  parent: ParentNode,
-) {
-  insertionAnchor = anchor as Node
+function initializeHydrationState(parent: ParentNode) {
   if (!hydrationStateCache.has(parent)) {
     const childNodes = parent.childNodes
     const len = childNodes.length
@@ -90,14 +95,7 @@ function initializeHydrationState(
   }
 }
 
-function cacheTemplateChildren(
-  anchor: number | Node | null | undefined,
-  parent: InsertionParent,
-) {
-  // special handling append anchor value to null
-  insertionAnchor =
-    typeof anchor === 'number' && anchor > 0 ? null : (anchor as Node)
-
+function cacheTemplateChildren(parent: InsertionParent) {
   if (!parent.$children) {
     const nodes = parent.childNodes
     const len = nodes.length