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

index 0b74f2f525902fa9032311744c1aec39f90e20d2..def2ef3bf0cf95c7ee4d8426f1f90965e04528b9 100644 (file)
@@ -67,9 +67,13 @@ export class DynamicFragment extends VaporFragment {
 
     if (this.fallback && !isValidBlock(this.nodes)) {
       parent && remove(this.nodes, parent)
-      this.nodes =
-        (this.scope || (this.scope = new EffectScope())).run(this.fallback) ||
-        []
+      if (isFragment(this.nodes)) {
+        renderFallback(this.nodes, this.fallback, key)
+      } else {
+        this.nodes =
+          (this.scope || (this.scope = new EffectScope())).run(this.fallback) ||
+          []
+      }
       parent && insert(this.nodes, parent, this.anchor)
     }
 
@@ -77,6 +81,24 @@ export class DynamicFragment extends VaporFragment {
   }
 }
 
+function renderFallback(
+  fragment: VaporFragment,
+  fallback: BlockFn,
+  key: any,
+): void {
+  if (fragment instanceof DynamicFragment) {
+    const nodes = fragment.nodes
+    if (isFragment(nodes)) {
+      renderFallback(nodes, fallback, key)
+    } else {
+      if (!fragment.fallback) fragment.fallback = fallback
+      fragment.update(fragment.fallback, key)
+    }
+  } else if (!fragment.fallback) {
+    fragment.fallback = fallback
+  }
+}
+
 export function isFragment(val: NonNullable<unknown>): val is VaporFragment {
   return val instanceof VaporFragment
 }
index 5ccbe6be89c8249683c98e40c863f5cbf4825304..c5d2219606bd0dc6e33195502d1f3536d6ff9716 100644 (file)
@@ -1,12 +1,5 @@
 import { EMPTY_OBJ, NO, hasOwn, isArray, isFunction } from '@vue/shared'
-import {
-  type Block,
-  type BlockFn,
-  DynamicFragment,
-  type VaporFragment,
-  insert,
-  isFragment,
-} from './block'
+import { type Block, type BlockFn, DynamicFragment, insert } from './block'
 import { rawPropsProxyHandlers } from './componentProps'
 import { currentInstance, isRef } from '@vue/runtime-dom'
 import type { LooseRawProps, VaporComponentInstance } from './component'
@@ -144,6 +137,7 @@ export function createSlot(
     const renderSlot = () => {
       const slot = getSlot(rawSlots, isFunction(name) ? name() : name)
       if (slot) {
+        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(
@@ -151,27 +145,8 @@ export function createSlot(
             (slot._bound = () => {
               const slotContent = slot(slotProps)
               if (slotContent instanceof DynamicFragment) {
-                let nodes = slotContent.nodes
-                if (
-                  (slotContent.fallback = fallback) &&
-                  isArray(nodes) &&
-                  nodes.length === 0
-                ) {
-                  // use fallback if the slot content is invalid
-                  slotContent.update(fallback)
-                } else {
-                  while (isFragment(nodes)) {
-                    ensureVaporSlotFallback(nodes, fallback)
-                    nodes = nodes.nodes
-                  }
-                }
-              }
-              // forwarded vdom slot, if there is no fallback provide, try use the fallback
-              // provided by the slot outlet.
-              else if (isFragment(slotContent)) {
-                ensureVaporSlotFallback(slotContent, fallback)
+                slotContent.fallback = fallback
               }
-
               return slotContent
             }),
         )
@@ -194,12 +169,3 @@ export function createSlot(
 
   return fragment
 }
-
-function ensureVaporSlotFallback(
-  block: VaporFragment,
-  fallback?: VaporSlot,
-): void {
-  if (block.insert && !block.fallback && fallback) {
-    block.fallback = fallback
-  }
-}