Skip to content

Commit a15f39c

Browse files
committed
Optimize init_hydrate
Do not create array from children if not needed
1 parent 35a7a20 commit a15f39c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/runtime/internal/dom.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,20 @@ function init_hydrate(target: NodeEx) {
3737

3838
type NodeEx2 = NodeEx & {claim_order: number};
3939

40-
// We know that all children have claim_order values since the unclaimed have been detached
41-
const children = Array.from(target.childNodes as NodeListOf<NodeEx>).filter(x => x.claim_order !== undefined) as NodeEx2[];
40+
// We know that all children have claim_order values since the unclaimed have been detached if target is not head
41+
let children: ArrayLike<NodeEx2> = target.childNodes as NodeListOf<NodeEx2>;
42+
43+
// If target is head, there may be children without claim_order
44+
if (target.nodeName.toLowerCase() == "head") {
45+
const myChildren = [];
46+
for (let i = 0; i < children.length; i++) {
47+
const node = children[i];
48+
if (node.claim_order !== undefined) {
49+
myChildren.push(node)
50+
}
51+
}
52+
children = myChildren;
53+
}
4254

4355
/*
4456
* Reorder claimed children optimally.

0 commit comments

Comments
 (0)