Skip to content

Commit b5396b4

Browse files
author
RicardoErii
committed
fix(runtime-dom): functions returned by withKeys should not support reuse
1 parent 4e7967f commit b5396b4

File tree

1 file changed

+30
-33
lines changed
  • packages/runtime-dom/src/directives

1 file changed

+30
-33
lines changed

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

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const keyNames: Record<string, string | string[]> = {
6666
* @private
6767
*/
6868
export const withKeys = <T extends (event: KeyboardEvent) => any>(
69-
fn: T & { _withKeys?: T },
69+
fn: T,
7070
modifiers: string[]
7171
) => {
7272
let globalKeyCodes: LegacyConfig['keyCodes']
@@ -88,43 +88,40 @@ export const withKeys = <T extends (event: KeyboardEvent) => any>(
8888
}
8989
}
9090

91-
return (
92-
fn._withKeys ||
93-
(fn._withKeys = (event => {
94-
if (!('key' in event)) {
95-
return
96-
}
91+
return (event => {
92+
if (!('key' in event)) {
93+
return
94+
}
95+
96+
const eventKey = hyphenate(event.key)
97+
if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
98+
return fn(event)
99+
}
97100

98-
const eventKey = hyphenate(event.key)
99-
if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
101+
if (__COMPAT__) {
102+
const keyCode = String(event.keyCode)
103+
if (
104+
compatUtils.isCompatEnabled(
105+
DeprecationTypes.V_ON_KEYCODE_MODIFIER,
106+
instance
107+
) &&
108+
modifiers.some(mod => mod == keyCode)
109+
) {
100110
return fn(event)
101111
}
102-
103-
if (__COMPAT__) {
104-
const keyCode = String(event.keyCode)
105-
if (
106-
compatUtils.isCompatEnabled(
107-
DeprecationTypes.V_ON_KEYCODE_MODIFIER,
108-
instance
109-
) &&
110-
modifiers.some(mod => mod == keyCode)
111-
) {
112-
return fn(event)
113-
}
114-
if (globalKeyCodes) {
115-
for (const mod of modifiers) {
116-
const codes = globalKeyCodes[mod]
117-
if (codes) {
118-
const matches = isArray(codes)
119-
? codes.some(code => String(code) === keyCode)
120-
: String(codes) === keyCode
121-
if (matches) {
122-
return fn(event)
123-
}
112+
if (globalKeyCodes) {
113+
for (const mod of modifiers) {
114+
const codes = globalKeyCodes[mod]
115+
if (codes) {
116+
const matches = isArray(codes)
117+
? codes.some(code => String(code) === keyCode)
118+
: String(codes) === keyCode
119+
if (matches) {
120+
return fn(event)
124121
}
125122
}
126123
}
127124
}
128-
}) as T)
129-
)
125+
}
126+
}) as T
130127
}

0 commit comments

Comments
 (0)