]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: create anchor for DynamicFragment in ssr slot vnode fallback edison/testVapor 13383/head
authordaiwei <daiwei521@126.com>
Sat, 2 Aug 2025 01:09:35 +0000 (09:09 +0800)
committerdaiwei <daiwei521@126.com>
Sat, 2 Aug 2025 01:18:22 +0000 (09:18 +0800)
packages/runtime-vapor/src/fragment.ts

index cee29ace4262a776f1373cf8f5f9a7ca20d39ea4..762e60e503efbc4da2b843eca3e8ff9e403a6bfe 100644 (file)
@@ -74,7 +74,7 @@ export class DynamicFragment extends VaporFragment {
 
   update(render?: BlockFn, key: any = render): void {
     if (key === this.current) {
-      if (isHydrating) this.hydrate(this.anchorLabel!, true)
+      if (isHydrating && this.anchorLabel) this.hydrate(this.anchorLabel!, true)
       return
     }
     this.current = key
@@ -155,30 +155,33 @@ export class DynamicFragment extends VaporFragment {
   }
 
   hydrate(label: string, isEmpty: boolean = false): void {
-    if (!label && isEmpty) return
-
-    // for `v-if="false"` the node will be an empty comment, use it as the anchor.
+    // for `v-if="false"`, the node will be an empty comment, use it as the anchor.
     // otherwise, find next sibling vapor fragment anchor
     if (label === 'if' && isEmpty) {
       this.anchor = locateVaporFragmentAnchor(currentHydrationNode!, '')!
     } else {
-      let anchor = locateVaporFragmentAnchor(currentHydrationNode!, label)!
-      if (!anchor) {
-        // TODO: comment anchors are not included in ssr slot vnode fallback
+      this.anchor = locateVaporFragmentAnchor(currentHydrationNode!, label)!
+      if (!this.anchor) {
+        // comment anchors are not included in ssr slot vnode fallback
         if (label === 'slot') {
           // fallback to fragment end anchor for
-          anchor = locateVaporFragmentAnchor(currentHydrationNode!, ']')!
-        } else if (label === 'if') {
+          this.anchor = locateVaporFragmentAnchor(currentHydrationNode!, ']')!
+        } else {
+          // create anchor
+          insert(
+            (this.anchor = __DEV__ ? createComment(label) : createTextNode()),
+            currentHydrationNode!.parentNode!,
+            currentHydrationNode!.nextSibling,
+          )
         }
       }
-      if (anchor) {
-        this.anchor = anchor
-      } else if (__DEV__) {
-        // this should not happen
-        throw new Error(`${label} fragment anchor node was not found.`)
-      }
     }
-    advanceHydrationNode(this.anchor)
+
+    if (this.anchor) {
+      advanceHydrationNode(this.anchor)
+    } else if (__DEV__) {
+      throw new Error(`${label} fragment anchor node was not found.`)
+    }
   }
 }