Skip to content

Commit 261de54

Browse files
authored
fix(runtime-dom): handle null/undefined handler in withModifiers (#14362)
close #14361
1 parent fc40ca0 commit 261de54

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

packages/runtime-dom/__tests__/directives/vOn.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,16 @@ describe('runtime-dom: v-on directive', () => {
163163
triggerEvent(el2, 'click', e => (e.shiftKey = true))
164164
expect(fn).toBeCalledTimes(2)
165165
})
166+
167+
it('withModifiers should handle null or undefined handler', () => {
168+
expect(() => {
169+
const handler1 = withModifiers(null as any, ['ctrl'])
170+
expect(handler1).toBe(null)
171+
}).not.toThrow()
172+
173+
expect(() => {
174+
const handler2 = withModifiers(undefined as any, ['shift'])
175+
expect(handler2).toBe(undefined)
176+
}).not.toThrow()
177+
})
166178
})

packages/runtime-dom/src/directives/vOn.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const withModifiers = <
5555
fn: T & { _withMods?: { [key: string]: T } },
5656
modifiers: VOnModifiers[],
5757
): T => {
58+
if (!fn) return fn
5859
const cache = fn._withMods || (fn._withMods = {})
5960
const cacheKey = modifiers.join('.')
6061
return (

0 commit comments

Comments
 (0)