Explorar el Código

chore: delay insert self anchor during hydration

daiwei hace 8 meses
padre
commit
0436ceac77

+ 0 - 11
packages/runtime-core/src/hydration.ts

@@ -659,17 +659,6 @@ export function createHydrationFunctions(
         )
         )
       }
       }
     }
     }
-
-    // the server output does not contain blank text nodes. It appears here that
-    // it is a dynamically inserted anchor, and needs to be skipped.
-    // e.g. vaporInteropImpl.mount() > selfAnchor
-    if (
-      node &&
-      node.nodeType === DOMNodeTypes.TEXT &&
-      !(node as Text).data.trim()
-    ) {
-      node = nextSibling(node)
-    }
     return node
     return node
   }
   }
 
 

+ 7 - 1
packages/runtime-vapor/src/vdomInterop.ts

@@ -24,6 +24,7 @@ import {
   isRef,
   isRef,
   isVNode,
   isVNode,
   onScopeDispose,
   onScopeDispose,
+  queuePostFlushCb,
   renderSlot,
   renderSlot,
   setTransitionHooks as setVNodeTransitionHooks,
   setTransitionHooks as setVNodeTransitionHooks,
   shallowReactive,
   shallowReactive,
@@ -74,7 +75,12 @@ const vaporInteropImpl: Omit<
 > = {
 > = {
   mount(vnode, container, anchor, parentComponent) {
   mount(vnode, container, anchor, parentComponent) {
     let selfAnchor = (vnode.el = vnode.anchor = createTextNode())
     let selfAnchor = (vnode.el = vnode.anchor = createTextNode())
-    container.insertBefore(selfAnchor, anchor)
+    if (isHydrating) {
+      // avoid vdom hydration children mismatch by the selfAnchor, delay its insertion
+      queuePostFlushCb(() => container.insertBefore(selfAnchor, anchor))
+    } else {
+      container.insertBefore(selfAnchor, anchor)
+    }
     const prev = currentInstance
     const prev = currentInstance
     simpleSetCurrentInstance(parentComponent)
     simpleSetCurrentInstance(parentComponent)