diff --git a/packages/runtime-vapor/src/dom/hydration.ts b/packages/runtime-vapor/src/dom/hydration.ts index fffdee6a5..855829fdd 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