From 78500909101989a71d2d91b47cb66bcba95663ed Mon Sep 17 00:00:00 2001 From: Phong Phan Date: Wed, 13 Nov 2024 06:10:48 -0500 Subject: [PATCH] fix: bind requestAnimationFrame and cancelAnimationFrame to window context (#322) --- src/utils.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 7818f76c..f1096d8c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -6,9 +6,10 @@ const globalObj = typeof window === 'undefined' ? global : window; export const performanceNow = (globalObj.performance && (() => globalObj.performance.now())) || (() => Date.now()); export const requestAnimationFrame = - globalObj.requestAnimationFrame || + globalObj.requestAnimationFrame?.bind(globalObj) || ((callback) => setTimeout(() => callback(performanceNow()), 1000 / 60)); -export const cancelAnimationFrame = globalObj.cancelAnimationFrame || clearTimeout; +export const cancelAnimationFrame = + globalObj.cancelAnimationFrame?.bind(globalObj) || clearTimeout; // Object.assign polyfill, because IE :/ export const _assign = function (target: any, ...overrides: any[]) {