]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(hydration): improve parent sibling lookup
authordaiwei <daiwei521@126.com>
Thu, 31 Jul 2025 09:48:45 +0000 (17:48 +0800)
committerdaiwei <daiwei521@126.com>
Thu, 31 Jul 2025 09:48:45 +0000 (17:48 +0800)
packages/runtime-vapor/src/dom/hydration.ts

index fffdee6a573cf5df40d267ee0c2ef25c0e131436..855829fddbcf5cadb040b4ce0c8daa8ecd854fe0 100644 (file)
@@ -20,10 +20,16 @@ export function setCurrentHydrationNode(node: Node | null): void {
   currentHydrationNode = node
 }
 
+function findParentSibling(n: Node): Node | null {
+  if (!n.parentNode) return null
+  const next = n.parentNode.nextSibling
+  return next ? next : findParentSibling(n.parentNode)
+}
+
 export function advanceHydrationNode(node: Node): void {
-  setCurrentHydrationNode(
-    node.nextSibling || (node.parentNode ? node.parentNode.nextSibling : null),
-  )
+  // if no next sibling, find the next node in the parent chain
+  const next = node.nextSibling || findParentSibling(node)
+  if (next) setCurrentHydrationNode(next)
 }
 
 let isOptimized = false