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)) {
|
if (this.fallback && !isValidBlock(this.nodes)) {
|
||||||
parent && remove(this.nodes, parent)
|
parent && remove(this.nodes, parent)
|
||||||
this.nodes =
|
if (isFragment(this.nodes)) {
|
||||||
(this.scope || (this.scope = new EffectScope())).run(this.fallback) ||
|
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)
|
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 {
|
export function isFragment(val: NonNullable<unknown>): val is VaporFragment {
|
||||||
return val instanceof VaporFragment
|
return val instanceof VaporFragment
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
import { EMPTY_OBJ, NO, hasOwn, isArray, isFunction } from '@vue/shared'
|
import { EMPTY_OBJ, NO, hasOwn, isArray, isFunction } from '@vue/shared'
|
||||||
import {
|
import { type Block, type BlockFn, DynamicFragment, insert } from './block'
|
||||||
type Block,
|
|
||||||
type BlockFn,
|
|
||||||
DynamicFragment,
|
|
||||||
type VaporFragment,
|
|
||||||
insert,
|
|
||||||
isFragment,
|
|
||||||
} from './block'
|
|
||||||
import { rawPropsProxyHandlers } from './componentProps'
|
import { rawPropsProxyHandlers } from './componentProps'
|
||||||
import { currentInstance, isRef } from '@vue/runtime-dom'
|
import { currentInstance, isRef } from '@vue/runtime-dom'
|
||||||
import type { LooseRawProps, VaporComponentInstance } from './component'
|
import type { LooseRawProps, VaporComponentInstance } from './component'
|
||||||
|
@ -144,6 +137,7 @@ export function createSlot(
|
||||||
const renderSlot = () => {
|
const renderSlot = () => {
|
||||||
const slot = getSlot(rawSlots, isFunction(name) ? name() : name)
|
const slot = getSlot(rawSlots, isFunction(name) ? name() : name)
|
||||||
if (slot) {
|
if (slot) {
|
||||||
|
fragment.fallback = fallback
|
||||||
// create and cache bound version of the slot to make it stable
|
// 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
|
// so that we avoid unnecessary updates if it resolves to the same slot
|
||||||
fragment.update(
|
fragment.update(
|
||||||
|
@ -151,27 +145,8 @@ export function createSlot(
|
||||||
(slot._bound = () => {
|
(slot._bound = () => {
|
||||||
const slotContent = slot(slotProps)
|
const slotContent = slot(slotProps)
|
||||||
if (slotContent instanceof DynamicFragment) {
|
if (slotContent instanceof DynamicFragment) {
|
||||||
let nodes = slotContent.nodes
|
slotContent.fallback = fallback
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
return slotContent
|
return slotContent
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
@ -194,12 +169,3 @@ export function createSlot(
|
||||||
|
|
||||||
return fragment
|
return fragment
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureVaporSlotFallback(
|
|
||||||
block: VaporFragment,
|
|
||||||
fallback?: VaporSlot,
|
|
||||||
): void {
|
|
||||||
if (block.insert && !block.fallback && fallback) {
|
|
||||||
block.fallback = fallback
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue