Skip to content

Commit 0690dee

Browse files
committed
chore: update
1 parent 532a988 commit 0690dee

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

packages/runtime-vapor/src/insertionState.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isHydrating } from './dom/hydration'
1+
import { isComment, isHydrating } from './dom/hydration'
22
export type ChildItem = ChildNode & {
33
$idx: number
44
// used count as an anchor
@@ -50,18 +50,30 @@ function initializeHydrationState(parent: ParentNode) {
5050
if (!hydrationStateCache.has(parent)) {
5151
const childNodes = parent.childNodes
5252
const len = childNodes.length
53+
54+
// fast path for single child case. No need to build logicalChildren
55+
if (
56+
len === 1 ||
57+
(len === 3 &&
58+
isComment(childNodes[0], '[') &&
59+
isComment(childNodes[2], ']'))
60+
) {
61+
insertionAnchor = undefined
62+
return
63+
}
64+
5365
const logicalChildren = new Array(len) as ChildItem[]
5466
// Build logical children:
5567
// - static node: keep the node as a child
5668
// - fragment: keep only the start anchor ('<!--[-->') as a child
5769
let index = 0
5870
for (let i = 0; i < len; i++) {
5971
const n = childNodes[i] as ChildItem
72+
n.$idx = index
6073
if (n.nodeType === 8) {
6174
const data = (n as any as Comment).data
6275
// vdom fragment
6376
if (data === '[') {
64-
n.$idx = index
6577
logicalChildren[index++] = n
6678
// find matching end anchor, accounting for nested fragments
6779
let depth = 1
@@ -82,7 +94,6 @@ function initializeHydrationState(parent: ParentNode) {
8294
continue
8395
}
8496
}
85-
n.$idx = index
8697
logicalChildren[index++] = n
8798
}
8899
logicalChildren.length = index

0 commit comments

Comments
 (0)