From 7bc88f30c3eadded07dd5b460d1e7cb9342d017c Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 6 Feb 2019 15:04:24 -0500 Subject: [PATCH] fix: skip microtask fix in Firefix <= 53 fix #9446 --- src/core/util/env.js | 1 + src/platforms/web/runtime/modules/events.js | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/util/env.js b/src/core/util/env.js index e89a2fc90..eff1d21dc 100644 --- a/src/core/util/env.js +++ b/src/core/util/env.js @@ -15,6 +15,7 @@ export const isAndroid = (UA && UA.indexOf('android') > 0) || (weexPlatform === export const isIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || (weexPlatform === 'ios') export const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge export const isPhantomJS = UA && /phantomjs/.test(UA) +export const isFF = UA && UA.match(/firefox\/(\d+)/) // Firefox has a "watch" function on Object.prototype... export const nativeWatch = ({}).watch diff --git a/src/platforms/web/runtime/modules/events.js b/src/platforms/web/runtime/modules/events.js index e7a969b64..2721a1fd5 100644 --- a/src/platforms/web/runtime/modules/events.js +++ b/src/platforms/web/runtime/modules/events.js @@ -2,7 +2,7 @@ import { isDef, isUndef } from 'shared/util' import { updateListeners } from 'core/vdom/helpers/index' -import { isIE, supportsPassive, isUsingMicroTask } from 'core/util/index' +import { isIE, isFF, supportsPassive, isUsingMicroTask } from 'core/util/index' import { RANGE_TOKEN, CHECKBOX_RADIO_TOKEN } from 'web/compiler/directives/model' import { currentFlushTimestamp } from 'core/observer/scheduler' @@ -39,6 +39,11 @@ function createOnceHandler (event, handler, capture) { } } +// #9446: Firefox <= 53 (in particular, ESR 52) has incorrect Event.timeStamp +// implementation and does not fire microtasks in between event propagation, so +// safe to exclude. +const useMicrotaskFix = isUsingMicroTask && !(isFF && Number(isFF[1]) <= 53) + function add ( name: string, handler: Function, @@ -51,7 +56,7 @@ function add ( // the solution is simple: we save the timestamp when a handler is attached, // and the handler would only fire if the event passed to it was fired // AFTER it was attached. - if (isUsingMicroTask) { + if (useMicrotaskFix) { const attachedTimestamp = currentFlushTimestamp const original = handler handler = original._wrapper = function (e) {