Skip to content

Commit

Permalink
refactor(jsx/dom): use for-loop instead of recursion for findInsertBe…
Browse files Browse the repository at this point in the history
…fore
  • Loading branch information
usualoma committed Aug 17, 2024
1 parent 967c2e6 commit 0dadfbc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/jsx/dom/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,14 @@ const getNextChildren = (
}

const findInsertBefore = (node: Node | undefined): SupportedElement | Text | null => {
return !node
? null
: node.tag === HONO_PORTAL_ELEMENT
? findInsertBefore(node.nN)
: node.e || (node.vC && node.pP && findInsertBefore(node.vC[0])) || findInsertBefore(node.nN)
for (; ; node = node.tag === HONO_PORTAL_ELEMENT || !node.vC || !node.pP ? node.nN : node.vC[0]) {
if (!node) {
return null
}
if (node.tag !== HONO_PORTAL_ELEMENT && node.e) {
return node.e
}
}
}

const removeNode = (node: Node): void => {
Expand Down

0 comments on commit 0dadfbc

Please sign in to comment.