Skip to content

Commit 3b49a63

Browse files
committed
adjust nextTick implementation (fix vuejs#3730)
1 parent b2ab9fa commit 3b49a63

File tree

1 file changed

+14
-34
lines changed

1 file changed

+14
-34
lines changed

src/util/env.js

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* global MutationObserver */
2-
31
// can we use __proto__?
42
export const hasProto = '__proto__' in {}
53

@@ -16,21 +14,6 @@ const UA = inBrowser && window.navigator.userAgent.toLowerCase()
1614
export const isIE = UA && UA.indexOf('trident') > 0
1715
export const isIE9 = UA && UA.indexOf('msie 9.0') > 0
1816
export const isAndroid = UA && UA.indexOf('android') > 0
19-
export const isIos = UA && /(iphone|ipad|ipod|ios)/i.test(UA)
20-
export const iosVersionMatch = isIos && UA.match(/os ([\d_]+)/)
21-
export const iosVersion = iosVersionMatch && iosVersionMatch[1].split('_').map(Number)
22-
23-
// MutationObserver is unreliable in iOS 9.3 UIWebView
24-
// detecting it by checking presence of IndexedDB
25-
// ref #3027
26-
const hasMutationObserverBug =
27-
iosVersion &&
28-
!window.indexedDB && (
29-
iosVersion[0] > 9 || (
30-
iosVersion[0] === 9 &&
31-
iosVersion[1] >= 3
32-
)
33-
)
3417

3518
let transitionProp
3619
let transitionEndEvent
@@ -89,27 +72,24 @@ export const nextTick = (function () {
8972
}
9073
}
9174

92-
/* istanbul ignore if */
93-
if (typeof MutationObserver !== 'undefined' && !hasMutationObserverBug) {
94-
var counter = 1
95-
var observer = new MutationObserver(nextTickHandler)
96-
var textNode = document.createTextNode(counter)
97-
observer.observe(textNode, {
98-
characterData: true
75+
/* istanbul ignore else */
76+
if (inBrowser && window.postMessage &&
77+
!window.importScripts && // not in WebWorker
78+
!(isAndroid && !window.requestAnimationFrame) // not in Android <= 4.3
79+
) {
80+
const NEXT_TICK_TOKEN = '__vue__nextTick__'
81+
window.addEventListener('message', e => {
82+
if (e.source === window && e.data === NEXT_TICK_TOKEN) {
83+
nextTickHandler()
84+
}
9985
})
100-
timerFunc = function () {
101-
counter = (counter + 1) % 2
102-
textNode.data = counter
86+
timerFunc = () => {
87+
window.postMessage(NEXT_TICK_TOKEN, '*')
10388
}
10489
} else {
105-
// webpack attempts to inject a shim for setImmediate
106-
// if it is used as a global, so we have to work around that to
107-
// avoid bundling unnecessary code.
108-
const context = inBrowser
109-
? window
110-
: typeof global !== 'undefined' ? global : {}
111-
timerFunc = context.setImmediate || setTimeout
90+
timerFunc = (typeof global !== 'undefined' && global.setImmediate) || setTimeout
11291
}
92+
11393
return function (cb, ctx) {
11494
var func = ctx
11595
? function () { cb.call(ctx) }

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy