Skip to content

feat: use queueMicrotask for nextTick timerFunc #10865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/core/util/next-tick.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ function flushCallbacks () {
let timerFunc

// The nextTick behavior leverages the microtask queue, which can be accessed
// via either native Promise.then or MutationObserver.
// via native WindowOrWorkerGlobalScope.queueMicrotask, Promise.then or MutationObserver.
// MutationObserver has wider support, however it is seriously bugged in
// UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It
// completely stops working after triggering a few times... so, if native
// Promise is available, we will use it:
// WindowOrWorkerGlobalScope.queueMicrotask or Promise is available, we will use native support by priority:
/* istanbul ignore next, $flow-disable-line */
if (typeof Promise !== 'undefined' && isNative(Promise)) {
if (typeof queueMicrotask !== 'undefined' && isNative(queueMicrotask)) {
timerFunc = () => {
queueMicrotask(flushCallbacks)
}
isUsingMicroTask = true
}
else if (typeof Promise !== 'undefined' && isNative(Promise)) {
const p = Promise.resolve()
timerFunc = () => {
p.then(flushCallbacks)
Expand Down