Skip to content

Commit 6dfc12d

Browse files
committed
chore: tweaks
1 parent f5a8fc5 commit 6dfc12d

File tree

2 files changed

+24
-40
lines changed

2 files changed

+24
-40
lines changed

packages/runtime-vapor/src/block.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,34 @@ export class DynamicFragment extends VaporFragment {
6767

6868
if (this.fallback && !isValidBlock(this.nodes)) {
6969
parent && remove(this.nodes, parent)
70-
this.nodes =
71-
(this.scope || (this.scope = new EffectScope())).run(this.fallback) ||
72-
[]
70+
if (isFragment(this.nodes)) {
71+
setFallback(this.nodes, this.fallback)
72+
} else {
73+
this.nodes =
74+
(this.scope || (this.scope = new EffectScope())).run(this.fallback) ||
75+
[]
76+
}
7377
parent && insert(this.nodes, parent, this.anchor)
7478
}
7579

7680
setActiveSub(prevSub)
7781
}
7882
}
7983

84+
function setFallback(fragment: VaporFragment, fallback: BlockFn): void {
85+
if (fragment instanceof DynamicFragment) {
86+
const nodes = fragment.nodes
87+
if (isFragment(nodes)) {
88+
setFallback(nodes, fallback)
89+
} else {
90+
if (!fragment.fallback) fragment.fallback = fallback
91+
fragment.update(fragment.fallback)
92+
}
93+
} else if (!fragment.fallback) {
94+
fragment.fallback = fallback
95+
}
96+
}
97+
8098
export function isFragment(val: NonNullable<unknown>): val is VaporFragment {
8199
return val instanceof VaporFragment
82100
}

packages/runtime-vapor/src/componentSlots.ts

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import { EMPTY_OBJ, NO, hasOwn, isArray, isFunction } from '@vue/shared'
2-
import {
3-
type Block,
4-
type BlockFn,
5-
DynamicFragment,
6-
type VaporFragment,
7-
insert,
8-
isFragment,
9-
} from './block'
2+
import { type Block, type BlockFn, DynamicFragment, insert } from './block'
103
import { rawPropsProxyHandlers } from './componentProps'
114
import { currentInstance, isRef } from '@vue/runtime-dom'
125
import type { LooseRawProps, VaporComponentInstance } from './component'
@@ -144,34 +137,16 @@ export function createSlot(
144137
const renderSlot = () => {
145138
const slot = getSlot(rawSlots, isFunction(name) ? name() : name)
146139
if (slot) {
140+
fragment.fallback = fallback
147141
// create and cache bound version of the slot to make it stable
148142
// so that we avoid unnecessary updates if it resolves to the same slot
149143
fragment.update(
150144
slot._bound ||
151145
(slot._bound = () => {
152146
const slotContent = slot(slotProps)
153147
if (slotContent instanceof DynamicFragment) {
154-
let nodes = slotContent.nodes
155-
if (
156-
(slotContent.fallback = fallback) &&
157-
isArray(nodes) &&
158-
nodes.length === 0
159-
) {
160-
// use fallback if the slot content is invalid
161-
slotContent.update(fallback)
162-
} else {
163-
while (isFragment(nodes)) {
164-
ensureVaporSlotFallback(nodes, fallback)
165-
nodes = nodes.nodes
166-
}
167-
}
168-
}
169-
// forwarded vdom slot, if there is no fallback provide, try use the fallback
170-
// provided by the slot outlet.
171-
else if (isFragment(slotContent)) {
172-
ensureVaporSlotFallback(slotContent, fallback)
148+
slotContent.fallback = fallback
173149
}
174-
175150
return slotContent
176151
}),
177152
)
@@ -194,12 +169,3 @@ export function createSlot(
194169

195170
return fragment
196171
}
197-
198-
function ensureVaporSlotFallback(
199-
block: VaporFragment,
200-
fallback?: VaporSlot,
201-
): void {
202-
if (block.insert && !block.fallback && fallback) {
203-
block.fallback = fallback
204-
}
205-
}

0 commit comments

Comments
 (0)