]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore: tweaks
authordaiwei <daiwei521@126.com>
Fri, 25 Jul 2025 02:16:29 +0000 (10:16 +0800)
committerdaiwei <daiwei521@126.com>
Fri, 25 Jul 2025 02:16:29 +0000 (10:16 +0800)
packages/runtime-vapor/src/block.ts
packages/runtime-vapor/src/componentSlots.ts

index 0271c1c0087992d0de2dce80e46a99d649122914..90070762dba37518cf9a50a8300bdc031af0f64e 100644 (file)
@@ -73,38 +73,38 @@ export class DynamicFragment extends VaporFragment {
     }
 
     if (this.fallback) {
-      parent && remove(this.nodes, parent)
-      const scope = this.scope || (this.scope = new EffectScope())
-      scope.run(() => {
-        // handle nested fragment
-        if (isFragment(this.nodes)) {
-          ensureFallback(this.nodes, this.fallback!)
-        } else if (!isValidBlock(this.nodes)) {
-          this.nodes = this.fallback!() || []
+      // set fallback for nested fragments
+      const isFrag = isFragment(this.nodes)
+      if (isFrag) {
+        if (!(this.nodes as VaporFragment).fallback) {
+          ;(this.nodes as VaporFragment).fallback = this.fallback
         }
-      })
-
-      parent && insert(this.nodes, parent, this.anchor)
+      }
+
+      if (!isValidBlock(this.nodes)) {
+        parent && remove(this.nodes, parent)
+        const scope = this.scope || (this.scope = new EffectScope())
+        scope.run(() => {
+          if (isFrag) {
+            // render fragment's fallback
+            renderFragmentFallback(this.nodes as VaporFragment)
+          } else {
+            this.nodes = this.fallback!() || []
+          }
+        })
+        parent && insert(this.nodes, parent, this.anchor)
+      }
     }
 
     setActiveSub(prevSub)
   }
 }
 
-function ensureFallback(fragment: VaporFragment, fallback: BlockFn): void {
-  if (!fragment.fallback) fragment.fallback = fallback
-
-  if (fragment instanceof DynamicFragment) {
-    const nodes = fragment.nodes
-    if (isFragment(nodes)) {
-      ensureFallback(nodes, fallback)
-    } else if (!isValidBlock(nodes)) {
-      fragment.update(fragment.fallback)
-    }
-  } else if (fragment instanceof ForFragment) {
-    if (!isValidBlock(fragment.nodes[0])) {
-      fragment.nodes[0] = [fallback() || []] as Block[]
-    }
+function renderFragmentFallback(fragment: VaporFragment): void {
+  if (fragment instanceof ForFragment) {
+    fragment.nodes[0] = [fragment.fallback!() || []] as Block[]
+  } else if (fragment instanceof DynamicFragment) {
+    fragment.update(fragment.fallback)
   } else {
     // vdom slots
   }
index 4215548f2e6504f23d8dd11bb1a14c19770630ce..036cf670e404d64045ba8f4823a66611ad2bd3c9 100644 (file)
@@ -129,16 +129,7 @@ export function createSlot(
         fragment.fallback = fallback
         // create and cache bound version of the slot to make it stable
         // so that we avoid unnecessary updates if it resolves to the same slot
-        fragment.update(
-          slot._bound ||
-            (slot._bound = () => {
-              const slotContent = slot(slotProps)
-              if (slotContent instanceof DynamicFragment) {
-                slotContent.fallback = fallback
-              }
-              return slotContent
-            }),
-        )
+        fragment.update(slot._bound || (slot._bound = () => slot(slotProps)))
       } else {
         fragment.update(fallback)
       }