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