Repository navigation
fix(language-core): detect duplicate event listeners across name formats - #6094
Conversation
|
The language service plugin is not working for tsc environment. Could you try resolving this issue during the codegen phase in the |
…ving to the same event" This reverts commit 9e0bfbd.
|
Hello, Thanks for revising and merging! Definitely an elegant solution. |
|
In the past, I often did this by triggering an additional event while binding data. This change causes errors in the current version. May I ask why this is not recommended? <MyPicker v-model="result" @update:model-value="action" /> |
|
I guess you have |
|
With vue-tsc 3.3.4, which includes this change, the following are detected as With vue-tsc 3.3.3, they were not detected as errors. Any hint would be appreciated. Thanks. |
|
The fix will be released at next version. |
|
@adube Oh my God this has been driving me insane today! |
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [vue-tsc](https://github.com/vuejs/language-tools) ([source](https://github.com/vuejs/language-tools/tree/HEAD/packages/tsc)) | devDependencies | minor | [`3.2.7` → `3.3.7`](https://renovatebot.com/diffs/npm/vue-tsc/3.2.7/3.3.7) | --- ### Release Notes <details> <summary>vuejs/language-tools (vue-tsc)</summary> ### [`v3.3.7`](https://github.com/vuejs/language-tools/blob/HEAD/CHANGELOG.md#337-2026-07-08) [Compare Source](vuejs/language-tools@v3.3.6...v3.3.7) ##### language-core - **fix:** wrap single expression event handlers to avoid ASI after `return` ([#​6115](vuejs/language-tools#6115)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! ##### typescript-plugin - **fix:** filter const globals from template completions ### [`v3.3.6`](https://github.com/vuejs/language-tools/blob/HEAD/CHANGELOG.md#336-2026-06-30) [Compare Source](vuejs/language-tools@v3.3.5...v3.3.6) ##### language-core - **fix:** make generic component internal context inference type-safe across `.d.ts` boundary ([#​6104](vuejs/language-tools#6104)) - Thanks to [@​Holiden](https://github.com/Holiden)! - **fix:** do not treat non-trivial property accesses as compound - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** treat semicolon-terminated expressions as compound - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** preserve return types for compound event handlers - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** use `WeakMap` to cache inline TS ASTs - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** match upstream CSS `v-bind` parsing behavior - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** include setup bindings as potential component names ([#​6111](vuejs/language-tools#6111)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **perf:** reduce boundary code feature allocations - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **refactor:** centralize code features and deprecate `allCodeFeatures` - Thanks to [@​KazariEX](https://github.com/KazariEX)! ### [`v3.3.5`](https://github.com/vuejs/language-tools/blob/HEAD/CHANGELOG.md#335-2026-06-13) [Compare Source](vuejs/language-tools@v3.3.4...v3.3.5) ##### language-core - **fix:** include event modifiers in duplicate listener checks ([#​6097](vuejs/language-tools#6097)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! ### [`v3.3.4`](https://github.com/vuejs/language-tools/blob/HEAD/CHANGELOG.md#334-2026-06-08) [Compare Source](vuejs/language-tools@v3.3.3...v3.3.4) ##### language-core - **fix:** only exclude already-set props from inherited attrs when `checkRequiredFallthroughAttributes` is enabled ([#​6088](vuejs/language-tools#6088)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** camelize slot props regardless of `htmlAttributes` option ([#​6089](vuejs/language-tools#6089)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** detect duplicate event listeners across name formats ([#​6094](vuejs/language-tools#6094)) - Thanks to [@​whysopaul](https://github.com/whysopaul)! ##### language-service - **fix:** respect var hoisting for destructured props hints ([#​6092](vuejs/language-tools#6092)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! ##### typescript-plugin - **fix:** do not treat `class` and `style` as a boolean property ([#​6081](vuejs/language-tools#6081)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! ### [`v3.3.3`](https://github.com/vuejs/language-tools/blob/HEAD/CHANGELOG.md#333-2026-05-30) [Compare Source](vuejs/language-tools@v3.3.2...v3.3.3) ##### vscode - **fix:** prevent grammar scopes leakage in capitalized tags ([#​6073](vuejs/language-tools#6073)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** preserve TS auto imports behavior in Vue files ([#​6072](vuejs/language-tools#6072)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! ##### workspace - **fix:** read PR title from env in `auto-version` workflow to prevent injection ([#​6074](vuejs/language-tools#6074)) - Thanks to [@​arpitjain099](https://github.com/arpitjain099)! ### [`v3.3.2`](https://github.com/vuejs/language-tools/blob/HEAD/CHANGELOG.md#332-2026-05-25) [Compare Source](vuejs/language-tools@v3.3.1...v3.3.2) ##### language-core - **feat:** preserve literal types for inline `v-for` sources ([#​6067](vuejs/language-tools#6067)) - Thanks to [@​kkesidis](https://github.com/kkesidis)! - **fix:** align `v-bind` shorthand identifier skipping with interpolation - Thanks to [@​KazariEX](https://github.com/KazariEX)! ##### vscode - **feat:** transform tsserver content ([#​6062](vuejs/language-tools#6062)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** do not mark trailing slash in capitalized self-closing tags as invalid ([#​6065](vuejs/language-tools#6065)) - Thanks to [@​suisanka](https://github.com/suisanka)! ### [`v3.3.1`](https://github.com/vuejs/language-tools/blob/HEAD/CHANGELOG.md#331-2026-05-19) [Compare Source](vuejs/language-tools@v3.3.0...v3.3.1) ##### language-core - **fix:** avoid extraneous children error for conditional slots ([#​6056](vuejs/language-tools#6056)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! ##### language-service - **refactor:** replace scanner-based missing props hints detection with AST traversal - Thanks to [@​KazariEX](https://github.com/KazariEX)! ##### typescript-plugin - **fix:** get component prop details from symbols - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** skip unchecked JS identifiers in component props ([#​6055](vuejs/language-tools#6055)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! ##### vscode - **fix:** resolve typescript plugin path from resolved server path ([#​6058](vuejs/language-tools#6058)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! ### [`v3.3.0`](https://github.com/vuejs/language-tools/blob/HEAD/CHANGELOG.md#330-2026-05-18) [Compare Source](vuejs/language-tools@v3.2.9...v3.3.0) ##### language-core - **feat:** check required fallthrough attributes ([#​6049](vuejs/language-tools#6049)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** penetrate `v-if` branch fragments when collecting single root nodes - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **refactor:** rename `Sfc` APIs to `IR` - Thanks to [@​KazariEX](https://github.com/KazariEX)! ##### language-service - **fix:** reuse ASTs for define assignment suggestions - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** re-support `html.customData` ([#​5910](vuejs/language-tools#5910)) - Thanks to [@​Bomberus](https://github.com/Bomberus)! - **fix:** strip `=""` only for plain boolean props completion edits - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** reset to default data provider after running with vue data provider - Thanks to [@​KazariEX](https://github.com/KazariEX)! ##### typescript-plugin - **feat:** refine props completion logic to follow TS behavior ([#​5709](vuejs/language-tools#5709)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! ##### vscode - **fix:** include `extraFileExtensions` in tsserver `configure` request payload ([#​6048](vuejs/language-tools#6048)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** write typescript plugins at build time ([#​6050](vuejs/language-tools#6050)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** avoid infinite diagnostics on Vue files when project diagnostics is enabled ([#​6051](vuejs/language-tools#6051)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! ### [`v3.2.9`](https://github.com/vuejs/language-tools/blob/HEAD/CHANGELOG.md#329-2026-05-14) [Compare Source](vuejs/language-tools@v3.2.8...v3.2.9) ##### language-core - **fix:** do not process inline markdown syntax in semantic-aware segments ([#​6038](vuejs/language-tools#6038)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **perf:** rewrite a subset of template node transforms ([#​5769](vuejs/language-tools#5769)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! ##### vscode - **fix:** trigger file rename edits when moving folders with Vue files ([#​6046](vuejs/language-tools#6046)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! ##### workspace - **chore:** bump volar services to 0.0.71 ([#​6043](vuejs/language-tools#6043)) - Thanks to [@​TRIS-H](https://github.com/TRIS-H)! ### [`v3.2.8`](https://github.com/vuejs/language-tools/blob/HEAD/CHANGELOG.md#328-2026-05-04) [Compare Source](vuejs/language-tools@v3.2.7...v3.2.8) ##### language-core - **fix:** replace inline code blocks after sfc blocks processing ([#​6024](vuejs/language-tools#6024)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! - **fix:** support navigation for kebab-case declarations in `GlobalComponents` ([#​6026](vuejs/language-tools#6026)) - Thanks to [@​Gehbt](https://github.com/Gehbt)! ##### language-service - **feat:** support TS module resolution for SCSS `@import` navigation ([#​6033](vuejs/language-tools#6033)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! ##### typescript-plugin - **fix:** replace language service per-method overrides with a proxy ([#​6035](vuejs/language-tools#6035)) - Thanks to [@​KazariEX](https://github.com/KazariEX)! ##### vscode - **chore:** upgrade `reactive-vscode` to v1.0.1 ([#​6019](vuejs/language-tools#6019)) - Thanks to [@​kermanx](https://github.com/kermanx)! </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMzIuMSIsInVwZGF0ZWRJblZlciI6IjQzLjIwNC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Reviewed-on: https://git.baer.one/phbaer/dtvp/pulls/144
Problem
Vue normalizes event listener names when merging props. Both
@create-postand@createPostresolve to the same handler keyonCreatePostat runtime viamergeProps():The same applies to
update:events:Neither
vue(2)(duplicate attribute) norts-plugin(1117)(duplicate object property) catch this.vue(2)compares names literally, and the TypeScript codegen produces two different string keys ("onCreate-post"vs"onCreatePost"), so TypeScript does not see the conflict either.Root cause
mergeProps()normalizes allonXxxhandler keys viacamelize()before merging:However, in a single JSX/template object literal the compiler does not call
mergeProps— it emits a plain object where the keys come from the template verbatim. If both@create-postand@createPostappear on the same element, the codegen produces:TypeScript sees two different string keys and raises no error. At runtime Vue processes the vnode props through
mergePropswhich normalizes them, sohandlerAandhandlerBboth end up underonCreatePost, and both are called. This looks correct on the surface but is almost certainly a typo: two different handlers registered for what the author thought were two different events.What this PR adds
A new
@vue/language-serviceplugin (vue-duplicate-event-listeners) that detects this class of bug statically, at edit time.When two or more
v-onlisteners on the same component resolve to the same normalized key, the plugin highlights the duplicate(s) as an error:Duplicate event listener. vue(duplicate-event-listener).Only the second (and further) occurrence is flagged, consistent with how
vue(2)andts-plugin(1117)behave.Normalization rules
The plugin mirrors the exact normalization that
mergeProps()applies at runtime. All cases below are detected:@create-postonCreatePost@createPostonCreatePost(duplicate)@update:post-titleonUpdate:postTitle@update:postTitleonUpdate:postTitle(duplicate)@vue:before-mountonVnodeBeforeMount@vue:beforeMountonVnodeBeforeMount(duplicate)Design decisions
Only events, not props
Duplicate static props and
v-modelbindings are already covered:ts-plugin(1117)— fires when two props produce the same key in the codegen object literal (e.g.post-title="a" postTitle="b")ts-plugin(2783)— fires when a static prop conflicts with av-bindspread (e.g.post-title="a" v-bind="{ postTitle: 'b' }")Adding a third diagnostic for the same cases would produce redundant errors on the same attribute. This plugin covers only the gap that existing tools leave:
v-onlisteners.Only components, not native elements
The
tagType !== COMPONENTguard is intentional. On native HTML elements,@create-postand@createPostmap to two separateaddEventListenercalls with literally different event names. The browser does not normalize them: aCustomEventdispatched ascreate-postwill not trigger acreatePostlistener. The normalization is a Vue-only mechanism that only applies to component prop passing.Only static arguments
Dynamic event arguments (
@[eventName]="fn") are skipped. Their value is unknown at static analysis time, so no false positives are possible.v-onwithout argument is not coveredv-on="expr"stores an arbitrary JavaScript expression as an unparsed string in the AST (isStatic: false). Extracting keys from it would require a JS parser and would still fail for non-literal expressions (v-on="handlers",v-on="isAdmin ? a : b"). This is an intentional limitation consistent with how all other static analysis tools treat this syntax.First occurrence is the canonical one
When duplicates are found, only
entries[1..n]are flagged — the first listener by source position is treated as the original. This matches the convention ofvue(2)andts-plugin(1117).Severity is Error, not Warning
Other duplicate-attribute diagnostics in the same toolchain (
vue(2),ts-plugin(1117),ts-plugin(2783)) all use Error severity.Does not overlap with
vue(2)vue(2)(DUPLICATE_ATTRIBUTE from@vue/compiler-dom) fires only on literally identical attribute names. It does not normalize —@create-postand@createPostproduce novue(2)error. This plugin covers the orthogonal case: same normalized key, different literal names.The only apparent overlap appears when three listeners are present, e.g.:
Here
vue(2)fires on@createPost(third, literally duplicates the second), and this plugin fires on@createPost(second, normalized duplicate of@create-post) and@createPost(third). The second@createPostappears to have two errors. This is technically correct — it is simultaneously a normalized duplicate of@create-postand an exact duplicate of the third@createPost— and is not worth special-casing since three listeners for the same event on one component is an extreme edge case.Files changed
Test cases
Positive (must flag):
@create-post+@createPost— basic kebab vs camel@create-post+@create-post— identical names (regression: must not break existing behavior)@update:post-title+@update:postTitle— update events@vue:before-mount+@vue:beforeMount— vnode lifecycle hooksNegative (must not flag):
@create-post+@update:title— different events:title+@update:title— prop and event, different namespaces@[eventName]+@[eventName]— dynamic arguments<div @click @click>— native element