From 1b0818bcde5bfdd48006c2f1a0017c49bd5f55fa Mon Sep 17 00:00:00 2001 From: daiwei Date: Thu, 31 Jul 2025 17:48:45 +0800 Subject: [PATCH] fix(hydration): improve parent sibling lookup --- packages/runtime-vapor/src/dom/hydration.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/runtime-vapor/src/dom/hydration.ts b/packages/runtime-vapor/src/dom/hydration.ts index fffdee6a57..855829fddb 100644 --- a/packages/runtime-vapor/src/dom/hydration.ts +++ b/packages/runtime-vapor/src/dom/hydration.ts @@ -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 -- 2.47.2