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)
}
}
}
+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
}
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'
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(
(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
}),
)
return fragment
}
-
-function ensureVaporSlotFallback(
- block: VaporFragment,
- fallback?: VaporSlot,
-): void {
- if (block.insert && !block.fallback && fallback) {
- block.fallback = fallback
- }
-}