Skip to content

Commit

Permalink
fix: skip microtask fix in Firefix <= 53
Browse files Browse the repository at this point in the history
fix #9446
  • Loading branch information
yyx990803 committed Feb 6, 2019
1 parent 96a09aa commit 7bc88f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/core/util/env.js
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/platforms/web/runtime/modules/events.js
Expand Up @@ -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'

Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit 7bc88f3

Please sign in to comment.