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

This commit is contained in:
Nolan Lawson 2021-03-14 18:05:57 -07:00 committed by GitHub
parent 193db0aa15
commit 02019e9251
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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()