perf: use scheduling.isInputPending() (#1996)

avoid-db-import
Nolan Lawson 2021-03-14 18:05:57 -07:00 zatwierdzone przez GitHub
rodzic 193db0aa15
commit 02019e9251
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 11 dodań i 1 usunięć

Wyświetl plik

@ -15,9 +15,19 @@ function getRIC () {
return typeof requestIdleCallback !== 'undefined' ? requestIdleCallback : liteRIC
}
function getIsInputPending () {
return process.browser && navigator.scheduling && navigator.scheduling.isInputPending
? () => navigator.scheduling.isInputPending()
: () => false // just assume input is not pending on browsers that don't support this
}
const isInputPending = getIsInputPending()
function runTasks (deadline) {
mark('scheduleIdleTask:runTasks()')
while (taskQueue.length && deadline.timeRemaining() > 0) {
// Bail out early if our deadline has passed (probably ~50ms) or if there is input pending
// See https://web.dev/isinputpending/
while (taskQueue.length && deadline.timeRemaining() > 0 && !isInputPending()) {
const task = taskQueue.shift()
try {
task()