fix(runtime-dom/v-on): only block event handlers based on attach timestamp

fix #1565
This commit is contained in:
Evan You 2020-07-13 14:49:54 -04:00
parent 6b63ba2f45
commit 8b320cc12f

View File

@ -7,7 +7,7 @@ import { ErrorCodes } from 'packages/runtime-core/src/errorHandling'
interface Invoker extends EventListener {
value: EventValue
lastUpdated: number
attached: number
}
type EventValue = (Function | Function[]) & {
@ -103,7 +103,6 @@ export function patchEvent(
;(prevValue as EventValue).invoker = null
invoker.value = value
nextValue.invoker = invoker
invoker.lastUpdated = getNow()
} else {
addEventListener(
el,
@ -129,7 +128,7 @@ function createInvoker(
// and the handler would only fire if the event passed to it was fired
// AFTER it was attached.
const timeStamp = e.timeStamp || _getNow()
if (timeStamp >= invoker.lastUpdated - 1) {
if (timeStamp >= invoker.attached - 1) {
callWithAsyncErrorHandling(
patchStopImmediatePropagation(e, invoker.value),
instance,
@ -140,7 +139,7 @@ function createInvoker(
}
invoker.value = initialValue
initialValue.invoker = invoker
invoker.lastUpdated = getNow()
invoker.attached = getNow()
return invoker
}