diff --git a/src/utils/index.js b/src/utils/index.js index 8276184..6682c62 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -192,18 +192,20 @@ function measureScrollbar() { // Use requestIdleCallback() if available, else fall back to setTimeout(). // Throttle so as not to run too frequently. function throttleIdleTask(func) { - const queue = + const doIdleTask = typeof requestIdleCallback === 'function' ? requestIdleCallback : setTimeout - const clear = - typeof cancelIdleCallback === 'function' ? cancelIdleCallback : clearTimeout - let id + let running = false return function throttled() { - if (id) { - clear(id) + if (running) { + return } - id = queue(func) + running = true + doIdleTask(() => { + running = false + func() + }) } }