]> 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:58:26 +0000 (10:58 +0800)
packages/runtime-vapor/src/apiCreateFor.ts
packages/runtime-vapor/src/block.ts
packages/runtime-vapor/src/componentSlots.ts

index ac2a94f09267888afb527dd5a5a87a8416369a50..0f032e685e901dc1cc83236d4ef2440dcf9bb4d5 100644 (file)
@@ -152,7 +152,6 @@ export const createFor = (
         // render fallback nodes
         if (frag.fallback) {
           insert((frag.nodes[0] = frag.fallback()), parent!, parentAnchor)
-          oldBlocks = []
           isFallback = true
         }
       } else if (!getKey) {
@@ -341,9 +340,9 @@ export const createFor = (
 
     if (!isFallback) {
       frag.nodes = [(oldBlocks = newBlocks)]
-      if (parentAnchor) {
-        frag.nodes.push(parentAnchor)
-      }
+      if (parentAnchor) frag.nodes.push(parentAnchor)
+    } else {
+      oldBlocks = []
     }
     setActiveSub(prevSub)
   }
index 0271c1c0087992d0de2dce80e46a99d649122914..7c178e894b0ea7604fa814ee02ac49459e06c200 100644 (file)
@@ -73,38 +73,53 @@ 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!() || []
-        }
-      })
-
-      parent && insert(this.nodes, parent, this.anchor)
+      // set fallback for nested fragments
+      const isFrag = isFragment(this.nodes)
+      if (isFrag) {
+        setFragmentFallback(this.nodes as VaporFragment, this.fallback)
+      }
+
+      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
+function setFragmentFallback(
+  fragment: VaporFragment,
+  fallback: BlockFn | undefined,
+): void {
+  if (!fragment.fallback) {
+    fragment.fallback = fallback
+  }
+  if (isFragment(fragment.nodes)) {
+    setFragmentFallback(fragment.nodes, fallback)
+  }
+}
 
-  if (fragment instanceof DynamicFragment) {
+function renderFragmentFallback(fragment: VaporFragment): void {
+  if (fragment instanceof ForFragment) {
+    fragment.nodes[0] = [fragment.fallback!() || []] as Block[]
+  } else if (fragment instanceof DynamicFragment) {
     const nodes = fragment.nodes
     if (isFragment(nodes)) {
-      ensureFallback(nodes, fallback)
-    } else if (!isValidBlock(nodes)) {
+      renderFragmentFallback(nodes)
+    } else {
       fragment.update(fragment.fallback)
     }
-  } else if (fragment instanceof ForFragment) {
-    if (!isValidBlock(fragment.nodes[0])) {
-      fragment.nodes[0] = [fallback() || []] as Block[]
-    }
   } 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)
       }