@@ -14,7 +14,7 @@ export function end_hydrating() {
14
14
type NodeEx = Node & {
15
15
claim_order ?: number ,
16
16
hydrate_init ? : true ,
17
- actual_end_child ?: Node ,
17
+ actual_end_child ?: NodeEx ,
18
18
childNodes : NodeListOf < NodeEx > ,
19
19
} ;
20
20
@@ -38,7 +38,7 @@ function init_hydrate(target: NodeEx) {
38
38
type NodeEx2 = NodeEx & { claim_order : number } ;
39
39
40
40
// 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 [ ] ;
42
42
43
43
/*
44
44
* Reorder claimed children optimally.
@@ -119,8 +119,17 @@ export function append(target: NodeEx, node: NodeEx) {
119
119
if ( ( target . actual_end_child === undefined ) || ( ( target . actual_end_child !== null ) && ( target . actual_end_child . parentElement !== target ) ) ) {
120
120
target . actual_end_child = target . firstChild ;
121
121
}
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
+
122
128
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
+ }
124
133
} else {
125
134
target . actual_end_child = node . nextSibling ;
126
135
}
0 commit comments