chore: tweaks
ci / test (push) Waiting to run Details
ci / continuous-release (push) Waiting to run Details

This commit is contained in:
daiwei 2025-07-22 10:31:16 +08:00
parent 2ba4dc0d07
commit e28b96bea8
2 changed files with 78 additions and 4 deletions

View File

@ -561,5 +561,64 @@ describe('component: slots', () => {
await nextTick() await nextTick()
expect(html()).toBe('fallback<!--if--><!--slot-->') expect(html()).toBe('fallback<!--if--><!--slot-->')
}) })
test('render fallback with nested v-if ', async () => {
const Child = {
setup() {
return createSlot('default', null, () =>
document.createTextNode('fallback'),
)
},
}
const outerShow = ref(false)
const innerShow = ref(false)
const { html } = define({
setup() {
return createComponent(Child, null, {
default: () => {
return createIf(
() => outerShow.value,
() => {
return createIf(
() => innerShow.value,
() => {
return document.createTextNode('content')
},
)
},
)
},
})
},
}).render()
expect(html()).toBe('fallback<!--if--><!--slot-->')
outerShow.value = true
await nextTick()
expect(html()).toBe('fallback<!--if--><!--if--><!--slot-->')
innerShow.value = true
await nextTick()
expect(html()).toBe('content<!--if--><!--if--><!--slot-->')
innerShow.value = false
await nextTick()
expect(html()).toBe('fallback<!--if--><!--if--><!--slot-->')
outerShow.value = false
await nextTick()
expect(html()).toBe('fallback<!--if--><!--slot-->')
outerShow.value = true
await nextTick()
expect(html()).toBe('fallback<!--if--><!--if--><!--slot-->')
innerShow.value = true
await nextTick()
expect(html()).toBe('content<!--if--><!--if--><!--slot-->')
})
}) })
}) })

View File

@ -67,10 +67,9 @@ 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)
// if current nodes is a DynamicFragment, call its update with the fallback // handle nested dynamic fragment
// to handle nested dynamic fragment if (isFragment(this.nodes)) {
if (this.nodes instanceof DynamicFragment) { renderFallback(this.nodes, this.fallback, key)
this.nodes.update(this.fallback)
} else { } else {
this.nodes = this.nodes =
(this.scope || (this.scope = new EffectScope())).run(this.fallback) || (this.scope || (this.scope = new EffectScope())).run(this.fallback) ||
@ -83,6 +82,22 @@ 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)
}
}
}
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
} }