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(vue3): Fix the declared camelCase event cannot be recognized #2051

Merged
merged 2 commits into from
Feb 4, 2024

Conversation

Azurewarth0920
Copy link
Contributor

@Azurewarth0920 Azurewarth0920 commented Apr 13, 2023

Description

fix: #2046
fix: #2063
fix: #2060

Fix the declared camelCase event that cannot be recognized.

the declaredEmits are not normalized to kebab case, which results in the mismatching with the declared events on the parent component side.

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).

@@ -371,13 +371,14 @@ function processRefs (instance) {
function processEventListeners (instance) {
const emitsDefinition = instance.type.emits
const declaredEmits = Array.isArray(emitsDefinition) ? emitsDefinition : Object.keys(emitsDefinition ?? {})
const normalizedDeclaredEmits = declaredEmits.map(key => kebabize(key))
const keys = Object.keys(instance.vnode.props ?? {})
const result = []
for (const key of keys) {
const [prefix, ...eventNameParts] = key.split(/(?=[A-Z])/)
if (prefix === 'on') {
const eventName = eventNameParts.join('-').toLowerCase()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line makes the eventName kebabized.

But the variable declaredEmits is a mixed case array, which will cause a mismatch.

@lbineau
Copy link

lbineau commented Jul 10, 2023

Sale issue, it is quite misleading to have warnings from Vue Devtools if we use camelCase instead of kebab-case for events.

@Akryum Akryum merged commit 990367e into vuejs:main Feb 4, 2024
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants