Skip to content

Commit 5358bca

Browse files
authored
fix(custom-element): use PatchFlags.BAIL for slot when props are present (#13907)
close #13904
1 parent 836b829 commit 5358bca

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/runtime-core/src/helpers/renderSlot.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function renderSlot(
3737
isAsyncWrapper(currentRenderingInstance!.parent) &&
3838
currentRenderingInstance!.parent.ce)
3939
) {
40+
const hasProps = Object.keys(props).length > 0
4041
// in custom element mode, render <slot/> as actual slot outlets
4142
// wrap it with a fragment because in shadowRoot: false mode the slot
4243
// element gets replaced by injected content
@@ -47,7 +48,7 @@ export function renderSlot(
4748
Fragment,
4849
null,
4950
[createVNode('slot', props, fallback && fallback())],
50-
PatchFlags.STABLE_FRAGMENT,
51+
hasProps ? PatchFlags.BAIL : PatchFlags.STABLE_FRAGMENT,
5152
)
5253
)
5354
}

packages/runtime-dom/__tests__/customElement.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,33 @@ describe('defineCustomElement', () => {
638638
`<div><slot><div>fallback</div></slot></div><div><slot name="named"></slot></div>`,
639639
)
640640
})
641+
642+
test('render slot props', async () => {
643+
const foo = ref('foo')
644+
const E = defineCustomElement({
645+
render() {
646+
return [
647+
h(
648+
'div',
649+
null,
650+
renderSlot(this.$slots, 'default', { class: foo.value }),
651+
),
652+
]
653+
},
654+
})
655+
customElements.define('my-el-slot-props', E)
656+
container.innerHTML = `<my-el-slot-props><span>hi</span></my-el-slot-props>`
657+
const e = container.childNodes[0] as VueElement
658+
expect(e.shadowRoot!.innerHTML).toBe(
659+
`<div><slot class="foo"></slot></div>`,
660+
)
661+
662+
foo.value = 'bar'
663+
await nextTick()
664+
expect(e.shadowRoot!.innerHTML).toBe(
665+
`<div><slot class="bar"></slot></div>`,
666+
)
667+
})
641668
})
642669

643670
describe('provide/inject', () => {

0 commit comments

Comments
 (0)