Skip to content

Commit dbe1bd8

Browse files
committed
perf: don't initialize hydration state if no anchor
1 parent df2c42a commit dbe1bd8

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

packages/runtime-vapor/src/insertionState.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,23 @@ export function setInsertionState(
3030
anchor?: Node | 0 | null | number,
3131
): void {
3232
insertionParent = parent
33-
if (isHydrating) {
34-
initializeHydrationState(anchor, parent)
33+
34+
if (anchor !== undefined) {
35+
if (isHydrating) {
36+
insertionAnchor = anchor as Node
37+
initializeHydrationState(parent)
38+
} else {
39+
// special handling append anchor value to null
40+
insertionAnchor =
41+
typeof anchor === 'number' && anchor > 0 ? null : (anchor as Node)
42+
cacheTemplateChildren(parent)
43+
}
3544
} else {
36-
cacheTemplateChildren(anchor, parent)
45+
insertionAnchor = undefined
3746
}
3847
}
3948

40-
function initializeHydrationState(
41-
anchor: number | Node | null | undefined,
42-
parent: ParentNode,
43-
) {
44-
insertionAnchor = anchor as Node
49+
function initializeHydrationState(parent: ParentNode) {
4550
if (!hydrationStateCache.has(parent)) {
4651
const childNodes = parent.childNodes
4752
const len = childNodes.length
@@ -90,14 +95,7 @@ function initializeHydrationState(
9095
}
9196
}
9297

93-
function cacheTemplateChildren(
94-
anchor: number | Node | null | undefined,
95-
parent: InsertionParent,
96-
) {
97-
// special handling append anchor value to null
98-
insertionAnchor =
99-
typeof anchor === 'number' && anchor > 0 ? null : (anchor as Node)
100-
98+
function cacheTemplateChildren(parent: InsertionParent) {
10199
if (!parent.$children) {
102100
const nodes = parent.childNodes
103101
const len = nodes.length

0 commit comments

Comments
 (0)