Skip to content

Commit 87b73b6

Browse files
authored
fix(runtime-core): preserve once event listener name (#8341)
close: #8342
1 parent 027da6b commit 87b73b6

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎packages/runtime-core/__tests__/componentEmits.spec.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ describe('component: emit', () => {
509509
'test-event': null,
510510
fooBar: null,
511511
FooBaz: null,
512+
once: null,
512513
}
513514
expect(isEmitListener(options, 'onClick')).toBe(true)
514515
expect(isEmitListener(options, 'onclick')).toBe(false)
@@ -522,6 +523,10 @@ describe('component: emit', () => {
522523
expect(isEmitListener(options, 'onFooBar')).toBe(true)
523524
// PascalCase option
524525
expect(isEmitListener(options, 'onFooBaz')).toBe(true)
526+
// event name `once`
527+
expect(isEmitListener(options, 'onOnce')).toBe(true)
528+
// event name `once` with `.once` modifier
529+
expect(isEmitListener(options, 'onOnceOnce')).toBe(true)
525530
})
526531

527532
test('does not emit after unmount', async () => {

‎packages/runtime-core/src/componentEmits.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,10 @@ export function isEmitListener(
302302
if (__COMPAT__ && key.startsWith(compatModelEventPrefix)) {
303303
return true
304304
}
305-
306-
key = key.slice(2).replace(/Once$/, '')
305+
key = key.slice(2)
306+
// #8342 the `.once` modifier appends a `Once` suffix. Preserve the exact event
307+
// name `once`, while still stripping the suffix from `onOnceOnce`.
308+
key = key === 'Once' ? key : key.replace(/Once$/, '')
307309
return (
308310
hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
309311
hasOwn(options, hyphenate(key)) ||

0 commit comments

Comments
 (0)