Skip to content

Commit

Permalink
fix(jsx/dom): fix rerendering of portal elements
Browse files Browse the repository at this point in the history
  • Loading branch information
usualoma committed May 20, 2024
1 parent 7f309ec commit 8974135
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/jsx/dom/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ const getNextChildren = (
const findInsertBefore = (node: Node | undefined): ChildNode | null => {
if (!node) {
return null
} else if (node.tag === HONO_PORTAL_ELEMENT) {
return findInsertBefore(node.nN)
} else if (node.e) {
return node.e
}
Expand Down Expand Up @@ -325,7 +327,7 @@ const applyNodeObject = (node: NodeObject, container: Container) => {
const childNodes = container.childNodes
let offset =
findChildNodeIndex(childNodes, findInsertBefore(node.nN)) ??
findChildNodeIndex(childNodes, next.find((n) => n.e)?.e) ??
findChildNodeIndex(childNodes, next.find((n) => n.tag !== HONO_PORTAL_ELEMENT && n.e)?.e) ??
childNodes.length

for (let i = 0, len = next.length; i < len; i++, offset++) {
Expand All @@ -345,11 +347,9 @@ const applyNodeObject = (node: NodeObject, container: Container) => {
applyProps(el as HTMLElement, child.props, child.pP)
applyNode(child, el as HTMLElement)
}
if (
childNodes[offset] !== el &&
childNodes[offset - 1] !== child.e &&
child.tag !== HONO_PORTAL_ELEMENT
) {
if (child.tag === HONO_PORTAL_ELEMENT) {
offset--
} else if (childNodes[offset] !== el && childNodes[offset - 1] !== child.e) {
container.insertBefore(el, childNodes[offset] || null)
}
}
Expand Down

0 comments on commit 8974135

Please sign in to comment.