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(runtime-core): kebab-cased event handler as prop called on emit #9813

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

leoelz
Copy link

@leoelz leoelz commented Dec 11, 2023

close #9812

@@ -152,6 +152,9 @@ export function emit(
let handlerName
let handler =
props[(handlerName = toHandlerKey(event))] ||
// try kebab-case with on- (#9812)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, it is not recommended to use :on-some-event to pass events. This will be passed to the component as props. The design of vue intentionally distinguishes props from event , that is, props, uses the v-bind directive, and event uses the v-on directive. I recommend you to use v-on:some-event

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, but that's another issue, when a string is passed through an event handler prop (no matter kebab-case or camelCase) you can check in current version with camelCase
I know that is not recommended to use props to pass event handler, but as you can see in docs, currently it's supported for camelCase

Copy link
Member

@pikax pikax Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs are just to document that hidden behaviour, which is not recommended to be widely used! As it is stated in the docs:

Because of this, it is recommended to use emit('event') instead of props.onEvent when emitting events.

Behaviour might change, since is not stable.

Copy link
Author

@leoelz leoelz Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification @pikax, the issue is when using emit('event') and the listener is defined as a hyphenated prop :on-event (the recommended case for props).

If it is not in the spec, I'm OK about this PR being closed and the issue, and add some clarification in docs about it.

Copy link

github-actions bot commented Oct 9, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB (+63 B) 38.1 kB (+25 B) 34.3 kB (+87 B)
vue.global.prod.js 160 kB (+63 B) 58 kB (+24 B) 51.5 kB (-12 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 49.1 kB (+63 B) 19 kB (+24 B) 17.3 kB (+24 B)
createApp 55.7 kB (+63 B) 21.4 kB (+24 B) 19.6 kB (-27 B)
createSSRApp 59.7 kB (+63 B) 23.2 kB (+28 B) 21.1 kB (+70 B)
defineCustomElement 60.5 kB (+63 B) 23 kB (+24 B) 20.9 kB (+10 B)
overall 69.4 kB (+63 B) 26.5 kB (+27 B) 24.1 kB (+85 B)

Copy link

pkg-pr-new bot commented Oct 9, 2024

Open in Stackblitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@9813

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@9813

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@9813

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@9813

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@9813

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@9813

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@9813

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@9813

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@9813

vue

pnpm add https://pkg.pr.new/vue@9813

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@9813

commit: 4521a9f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kebab-cased event handler as prop not called on emit
4 participants