chore: tweaks
ci / test (push) Has been cancelled Details
ci / continuous-release (push) Has been cancelled Details

This commit is contained in:
daiwei 2025-07-25 22:15:47 +08:00
parent 92399d9f8f
commit 5b4673fccd
2 changed files with 6 additions and 22 deletions

View File

@ -98,9 +98,9 @@ export class DynamicFragment extends VaporFragment {
} }
} }
function setFragmentFallback( export function setFragmentFallback(
fragment: VaporFragment, fragment: VaporFragment,
fallback: BlockFn | undefined, fallback: BlockFn,
): void { ): void {
// stop recursion if fragment has its own fallback // stop recursion if fragment has its own fallback
if (fragment.fallback) return if (fragment.fallback) return

View File

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