mirror of https://github.com/vuejs/core.git
chore: tweaks
This commit is contained in:
parent
f5a8fc50aa
commit
e92244e719
|
@ -67,9 +67,13 @@ export class DynamicFragment extends VaporFragment {
|
|||
|
||||
if (this.fallback && !isValidBlock(this.nodes)) {
|
||||
parent && remove(this.nodes, parent)
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
slotContent.fallback = fallback
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue