fix(hydration): improve parent sibling lookup

This commit is contained in:
daiwei 2025-07-31 17:48:45 +08:00
parent 761b1617a7
commit 1b0818bcde
1 changed files with 9 additions and 3 deletions

View File

@ -20,10 +20,16 @@ export function setCurrentHydrationNode(node: Node | null): void {
currentHydrationNode = node 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 { export function advanceHydrationNode(node: Node): void {
setCurrentHydrationNode( // if no next sibling, find the next node in the parent chain
node.nextSibling || (node.parentNode ? node.parentNode.nextSibling : null), const next = node.nextSibling || findParentSibling(node)
) if (next) setCurrentHydrationNode(next)
} }
let isOptimized = false let isOptimized = false