]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix: ensure self anchor is inserted during hydration
authordaiwei <daiwei521@126.com>
Fri, 29 Aug 2025 08:53:00 +0000 (16:53 +0800)
committerdaiwei <daiwei521@126.com>
Fri, 29 Aug 2025 08:57:27 +0000 (16:57 +0800)
packages/runtime-vapor/src/vdomInterop.ts

index 39a9e07f7b508f46731663802c1750eda4261fb6..04a288118552130431d958f55b13ef127286c4b5 100644 (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)
   },
 
   /**