-import { isHydrating } from './dom/hydration'
+import { isComment, isHydrating } from './dom/hydration'
export type ChildItem = ChildNode & {
$idx: number
// used count as an anchor
if (!hydrationStateCache.has(parent)) {
const childNodes = parent.childNodes
const len = childNodes.length
+
+ // fast path for single child case. No need to build logicalChildren
+ if (
+ len === 1 ||
+ (len === 3 &&
+ isComment(childNodes[0], '[') &&
+ isComment(childNodes[2], ']'))
+ ) {
+ insertionAnchor = undefined
+ return
+ }
+
const logicalChildren = new Array(len) as ChildItem[]
// Build logical children:
// - static node: keep the node as a child
let index = 0
for (let i = 0; i < len; i++) {
const n = childNodes[i] as ChildItem
+ n.$idx = index
if (n.nodeType === 8) {
const data = (n as any as Comment).data
// vdom fragment
if (data === '[') {
- n.$idx = index
logicalChildren[index++] = n
// find matching end anchor, accounting for nested fragments
let depth = 1
continue
}
}
- n.$idx = index
logicalChildren[index++] = n
}
logicalChildren.length = index