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
3 changes: 2 additions & 1 deletion packages/runtime-core/src/helpers/renderSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function renderSlot(
isAsyncWrapper(currentRenderingInstance!.parent) &&
currentRenderingInstance!.parent.ce)
) {
const hasProps = Object.keys(props).length > 0
// in custom element mode, render <slot/> as actual slot outlets
// wrap it with a fragment because in shadowRoot: false mode the slot
// element gets replaced by injected content
Expand All @@ -47,7 +48,7 @@ export function renderSlot(
Fragment,
null,
[createVNode('slot', props, fallback && fallback())],
PatchFlags.STABLE_FRAGMENT,
hasProps ? PatchFlags.BAIL : PatchFlags.STABLE_FRAGMENT,
)
)
}
Expand Down
27 changes: 27 additions & 0 deletions packages/runtime-dom/__tests__/customElement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,33 @@ describe('defineCustomElement', () => {
`<div><slot><div>fallback</div></slot></div><div><slot name="named"></slot></div>`,
)
})

test('render slot props', async () => {
const foo = ref('foo')
const E = defineCustomElement({
render() {
return [
h(
'div',
null,
renderSlot(this.$slots, 'default', { class: foo.value }),
),
]
},
})
customElements.define('my-el-slot-props', E)
container.innerHTML = `<my-el-slot-props><span>hi</span></my-el-slot-props>`
const e = container.childNodes[0] as VueElement
expect(e.shadowRoot!.innerHTML).toBe(
`<div><slot class="foo"></slot></div>`,
)

foo.value = 'bar'
await nextTick()
expect(e.shadowRoot!.innerHTML).toBe(
`<div><slot class="bar"></slot></div>`,
)
})
})

describe('provide/inject', () => {
Expand Down
Loading