]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore: tweaks edison/feat/fowardedSlots 13408/head
authordaiwei <daiwei521@126.com>
Fri, 25 Jul 2025 14:15:47 +0000 (22:15 +0800)
committerdaiwei <daiwei521@126.com>
Fri, 25 Jul 2025 14:15:47 +0000 (22:15 +0800)
packages/runtime-vapor/src/block.ts
packages/runtime-vapor/src/vdomInterop.ts

index cdc562e32d3a0d6da314aefa58c2c44e9ed9a1cd..9ccb0fb26a58fc365f89d79c0a14ed273d0d7f1d 100644 (file)
@@ -98,9 +98,9 @@ export class DynamicFragment extends VaporFragment {
   }
 }
 
-function setFragmentFallback(
+export function setFragmentFallback(
   fragment: VaporFragment,
-  fallback: BlockFn | undefined,
+  fallback: BlockFn,
 ): void {
   // stop recursion if fragment has its own fallback
   if (fragment.fallback) return
index 8dafdeaaf6a1d5abc0bec59786cb8a777fa65b6f..eb579a23beaff3dcb187c88544ba0a2235e2865f 100644 (file)
@@ -35,11 +35,11 @@ import {
 } from './component'
 import {
   type Block,
-  DynamicFragment,
   VaporFragment,
   insert,
   isFragment,
   remove,
+  setFragmentFallback,
 } from './block'
 import { EMPTY_OBJ, extend, isArray, isFunction } from '@vue/shared'
 import { type RawProps, rawPropsProxyHandlers } from './componentProps'
@@ -116,22 +116,12 @@ const vaporInteropImpl: Omit<
       const { slot, fallback } = n2.vs!
       const propsRef = (n2.vs!.ref = shallowRef(n2.props))
       const slotBlock = slot(new Proxy(propsRef, vaporSlotPropsProxyHandler))
-      // forwarded vdom slot without its own fallback, use the fallback provided by
-      // the slot outlet
-      if (slotBlock instanceof DynamicFragment) {
-        // vapor slot's nodes is a forwarded vdom slot
-        let nodes = slotBlock.nodes
-        while (isFragment(nodes)) {
-          ensureVDOMSlotFallback(nodes, fallback)
-          nodes = nodes.nodes
-        }
+      // handle nested fragments
+      if (fallback && isFragment(slotBlock)) {
+        setFragmentFallback(slotBlock, createFallback(fallback))
         // use fragment's anchor when possible
         selfAnchor = slotBlock.anchor
-      } else if (isFragment(slotBlock)) {
-        ensureVDOMSlotFallback(slotBlock, fallback)
-        selfAnchor = slotBlock.anchor!
       }
-
       if (!selfAnchor) selfAnchor = createTextNode()
       insert((n2.el = n2.anchor = selfAnchor), container, anchor)
       insert((n2.vb = slotBlock), container, selfAnchor)
@@ -356,12 +346,6 @@ export const vaporInteropPlugin: Plugin = app => {
   }) satisfies App['mount']
 }
 
-function ensureVDOMSlotFallback(block: VaporFragment, fallback?: () => any) {
-  if (block.insert && !block.fallback && fallback) {
-    block.fallback = createFallback(fallback)
-  }
-}
-
 const createFallback =
   (fallback: () => any) =>
   (