Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(customElement): customElement can emit event #7296

Merged
merged 2 commits into from Dec 23, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/runtime-core/src/vnode.ts
Expand Up @@ -672,7 +672,8 @@ export function cloneVNode<T, U>(
ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
el: vnode.el,
anchor: vnode.anchor,
ctx: vnode.ctx
ctx: vnode.ctx,
ce: vnode.ce
}
if (__COMPAT__) {
defineLegacyVNodeProperties(cloned as VNode)
Expand Down
19 changes: 19 additions & 0 deletions packages/runtime-dom/__tests__/customElement.spec.ts
Expand Up @@ -384,6 +384,25 @@ describe('defineCustomElement', () => {
detail: [1]
})
})
// #7293
test('emit in an async component wrapper with properties bound', async () => {
const E = defineCustomElement(
defineAsyncComponent(
() => new Promise<typeof CompDef>(res => res(CompDef as any))
)
)
customElements.define('my-async-el-props-emits', E)
container.innerHTML = `<my-async-el-props-emits id="my_async_el_props_emits"></my-async-el-props-emits>`
const e = container.childNodes[0] as VueElement
const spy = jest.fn()
e.addEventListener('my-click', spy)
await customElements.whenDefined('my-async-el-props-emits')
e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
expect(spy).toHaveBeenCalled()
expect(spy.mock.calls[0][0]).toMatchObject({
detail: [1]
})
})
})

describe('slots', () => {
Expand Down