From: daiwei Date: Tue, 22 Jul 2025 02:22:19 +0000 (+0800) Subject: chore: tweaks X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e92244e719788db07803c100eb3c88b7ba8b6cb6;p=thirdparty%2Fvuejs%2Fcore.git chore: tweaks --- diff --git a/packages/runtime-vapor/src/block.ts b/packages/runtime-vapor/src/block.ts index 0b74f2f525..def2ef3bf0 100644 --- a/packages/runtime-vapor/src/block.ts +++ b/packages/runtime-vapor/src/block.ts @@ -67,9 +67,13 @@ export class DynamicFragment extends VaporFragment { 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) } @@ -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): val is VaporFragment { return val instanceof VaporFragment } diff --git a/packages/runtime-vapor/src/componentSlots.ts b/packages/runtime-vapor/src/componentSlots.ts index 5ccbe6be89..c5d2219606 100644 --- a/packages/runtime-vapor/src/componentSlots.ts +++ b/packages/runtime-vapor/src/componentSlots.ts @@ -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 - } - } - } - // 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 }), ) @@ -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 - } -}