Skip to content

Commit 1df1597

Browse files
committed
fix: skip blank text nodes during hydration
1 parent df9f8f2 commit 1df1597

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

packages/runtime-core/src/hydration.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,17 @@ export function createHydrationFunctions(
659659
)
660660
}
661661
}
662+
663+
// the server output does not contain blank text nodes. It appears here that
664+
// it is a dynamically inserted anchor, and needs to be skipped.
665+
// e.g. vaporInteropImpl.mount() > selfAnchor
666+
if (
667+
node &&
668+
node.nodeType === DOMNodeTypes.TEXT &&
669+
!(node as Text).data.trim()
670+
) {
671+
node = nextSibling(node)
672+
}
662673
return node
663674
}
664675

packages/runtime-vapor/src/vdomInterop.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ const vaporInteropImpl: Omit<
6262
> = {
6363
mount(vnode, container, anchor, parentComponent) {
6464
let selfAnchor = (vnode.el = vnode.anchor = createTextNode())
65-
if (!isHydrating) {
66-
container.insertBefore(selfAnchor, anchor)
67-
}
65+
container.insertBefore(selfAnchor, anchor)
6866
const prev = currentInstance
6967
simpleSetCurrentInstance(parentComponent)
7068

@@ -90,12 +88,6 @@ const vaporInteropImpl: Omit<
9088
))
9189
instance.rawPropsRef = propsRef
9290
instance.rawSlotsRef = slotsRef
93-
if (isHydrating) {
94-
// insert self anchor after hydration completed to avoid mismatching
95-
;(instance.m || (instance.m = [])).push(() => {
96-
container.insertBefore(selfAnchor, anchor)
97-
})
98-
}
9991
mountComponent(instance, container, selfAnchor)
10092
simpleSetCurrentInstance(prev)
10193
return instance

0 commit comments

Comments
 (0)