Skip to content

Commit

Permalink
fix(runtime-dom): ensure customElement handles empty props correctly. (
Browse files Browse the repository at this point in the history
…vuejs#6182)

fix Scoped attribute in Vue file affects the use of web component vuejs#6163,vuejs#6895
  • Loading branch information
LinusBorg authored and chrislone committed Feb 4, 2023
1 parent 97b963c commit 4897af9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/runtime-dom/__tests__/customElement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@ describe('defineCustomElement', () => {
customElements.define('my-el-upgrade', E)
expect(el.shadowRoot.innerHTML).toBe(`foo: hello`)
})

// https://github.com/vuejs/core/issues/6163
test('handle components with no props', async () => {
const E = defineCustomElement({
render() {
return h('div', 'foo')
}
})
customElements.define('my-element-noprops', E)
const el = document.createElement('my-element-noprops')
container.appendChild(el)
await nextTick()
expect(el.shadowRoot!.innerHTML).toMatchInlineSnapshot('"<div>foo</div>"')
})
})

describe('emits', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-dom/src/apiCustomElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class VueElement extends BaseClass {
}).observe(this, { attributes: true })

const resolve = (def: InnerComponentDef) => {
const { props, styles } = def
const { props = {}, styles } = def
const hasOptions = !isArray(props)
const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : []

Expand Down

0 comments on commit 4897af9

Please sign in to comment.