Skip to content

Commit

Permalink
fix(renderer): add check for already relocated nodes to avoid reordering
Browse files Browse the repository at this point in the history
another check is added to avoid changing already relocated nodes order by updating the anchor node which is used by insertBefore

fixes one of the issues raised in ionic-team#5335
  • Loading branch information
yigityuce committed Feb 24, 2024
1 parent c69160e commit 5e4e780
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/runtime/vdom/vdom-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1048,20 +1048,23 @@ render() {
!BUILD.experimentalSlotFixes ||
(insertBeforeNode && insertBeforeNode.nodeType === NODE_TYPE.ElementNode)
) {
let orgLocationNode = nodeToRelocate['s-ol']?.previousSibling as d.RenderNode | null;

while (orgLocationNode) {
let refNode = orgLocationNode['s-nr'] ?? null;

if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
refNode = refNode.nextSibling as any;
if (!refNode || !refNode['s-nr']) {
insertBeforeNode = refNode;
break;
// first check the relocating node has already a reference node since the node might have already been
// relocated. So in that case we already have a correct order and do NOT need to change the order
if (!nodeToRelocate['s-ol']?.['s-nr']) {
let orgLocationNode = nodeToRelocate['s-ol']?.previousSibling as d.RenderNode | null;
while (orgLocationNode) {
let refNode = orgLocationNode['s-nr'] ?? null;

if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
refNode = refNode.nextSibling as any;
if (!refNode || !refNode['s-nr']) {
insertBeforeNode = refNode;
break;
}
}
}

orgLocationNode = orgLocationNode.previousSibling as d.RenderNode | null;
orgLocationNode = orgLocationNode.previousSibling as d.RenderNode | null;
}
}
}

Expand Down

0 comments on commit 5e4e780

Please sign in to comment.