Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions packages/runtime-vapor/__tests__/apiCreateDynamicComponent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,35 @@ describe('api: createDynamicComponent', () => {
await nextTick()
expect(html()).toBe('<div><div>B</div><!--dynamic-component--></div>')
})

test('fallback with dynamic slots', async () => {
const slotName = ref('default')
const { html } = define({
setup() {
return createDynamicComponent(() => 'div', null, {
$: [
() => ({
name: slotName.value,
fn: () => template('<span>hi</span>')(),
}),
] as any,
})
},
}).render()

expect(html()).toBe(
'<div><span>hi</span><!--slot--></div><!--dynamic-component-->',
)

// update slot name
slotName.value = 'custom'
await nextTick()
expect(html()).toBe('<div><!--slot--></div><!--dynamic-component-->')

slotName.value = 'default'
await nextTick()
expect(html()).toBe(
'<div><span>hi</span><!--slot--></div><!--dynamic-component-->',
)
})
})
28 changes: 28 additions & 0 deletions packages/runtime-vapor/__tests__/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,34 @@ describe('Vapor Mode hydration', () => {
`,
)
})

test('dynamic component fallback with dynamic slots', async () => {
const data = ref({
name: 'default',
msg: 'foo',
})
const { container } = await testHydration(
`<template>
<component :is="'div'">
<template v-slot:[data.name]>
<span>{{ data.msg }}</span>
</template>
</component>
</template>`,
{},
data,
)

expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot(
`"<div><span>foo</span><!----></div><!--dynamic-component-->"`,
)

data.value.msg = 'bar'
await nextTick()
expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot(
`"<div><span>bar</span><!----></div><!--dynamic-component-->"`,
)
})
})

describe('if', () => {
Expand Down
11 changes: 9 additions & 2 deletions packages/runtime-vapor/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,16 @@ export function createComponentWithFallback(
setCurrentHydrationNode(el.firstChild)
}
if (rawSlots.$) {
// TODO dynamic slot fragment
// ssr output does not contain the slot anchor, use an empty string
// as the anchor label to avoid slot anchor search errors
const frag = new DynamicFragment(
isHydrating ? '' : __DEV__ ? 'slot' : undefined,
)
renderEffect(() => frag.update(getSlot(rawSlots as RawSlots, 'default')))
if (!isHydrating) insert(frag, el)
} else {
insert(getSlot(rawSlots as RawSlots, 'default')!(), el)
const block = getSlot(rawSlots as RawSlots, 'default')!()
if (!isHydrating) insert(block, el)
}
if (isHydrating) {
setCurrentHydrationNode(nextNode)
Expand Down
Loading