Skip to content

Commit d5e2a90

Browse files
committed
Skip reordering of unclaimed nodes in hydration
1 parent 51abdbf commit d5e2a90

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/runtime/internal/dom.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function end_hydrating() {
1414
type NodeEx = Node & {
1515
claim_order?: number,
1616
hydrate_init? : true,
17-
actual_end_child?: Node,
17+
actual_end_child?: NodeEx,
1818
childNodes: NodeListOf<NodeEx>,
1919
};
2020

@@ -38,7 +38,7 @@ function init_hydrate(target: NodeEx) {
3838
type NodeEx2 = NodeEx & {claim_order: number};
3939

4040
// We know that all children have claim_order values since the unclaimed have been detached
41-
const children = target.childNodes as NodeListOf<NodeEx2>;
41+
const children = Array.from(target.childNodes as NodeListOf<NodeEx>).filter(x => x.claim_order !== undefined) as NodeEx2[];
4242

4343
/*
4444
* Reorder claimed children optimally.
@@ -119,8 +119,17 @@ export function append(target: NodeEx, node: NodeEx) {
119119
if ((target.actual_end_child === undefined) || ((target.actual_end_child !== null) && (target.actual_end_child.parentElement !== target))) {
120120
target.actual_end_child = target.firstChild;
121121
}
122+
123+
// Skip nodes of undefined ordering
124+
while ((target.actual_end_child !== null) && (target.actual_end_child.claim_order === undefined)) {
125+
target.actual_end_child = target.actual_end_child.nextSibling;
126+
}
127+
122128
if (node !== target.actual_end_child) {
123-
target.insertBefore(node, target.actual_end_child);
129+
if (node.claim_order !== undefined || node.parentNode !== target) {
130+
// We only insert if the ordering of this node should be modified or the parent node is not target
131+
target.insertBefore(node, target.actual_end_child);
132+
}
124133
} else {
125134
target.actual_end_child = node.nextSibling;
126135
}

0 commit comments

Comments
 (0)