fix: ensure self anchor is inserted during hydration

This commit is contained in:
daiwei 2025-08-29 16:53:00 +08:00
parent 5ba35e7bc2
commit 8ea4ab1f1f
1 changed files with 8 additions and 3 deletions

View File

@ -74,9 +74,8 @@ const vaporInteropImpl: Omit<
'vdomMount' | 'vdomUnmount' | 'vdomSlot'
> = {
mount(vnode, container, anchor, parentComponent) {
let selfAnchor: Node | null = null
let selfAnchor = (vnode.el = vnode.anchor = createTextNode())
if (!isHydrating) {
selfAnchor = vnode.el = vnode.anchor = createTextNode()
container.insertBefore(selfAnchor, anchor)
}
const prev = currentInstance
@ -120,6 +119,12 @@ const vaporInteropImpl: Omit<
vnode.transition as VaporTransitionHooks,
)
}
if (isHydrating) {
// insert self anchor after hydration completed to avoid mismatching
;(instance.m || (instance.m = [])).push(() => {
container.insertBefore(selfAnchor, anchor)
})
}
mountComponent(instance, container, selfAnchor)
simpleSetCurrentInstance(prev)
return instance
@ -142,7 +147,7 @@ const vaporInteropImpl: Omit<
} else if (vnode.vb) {
remove(vnode.vb, container)
}
if (vnode.anchor) remove(vnode.anchor as Node, container)
remove(vnode.anchor as Node, container)
},
/**