From 34d33ad6c512ef39395ee49fc5c0843c9ffb1dc0 Mon Sep 17 00:00:00 2001 From: Brandon Ly Date: Sun, 24 Sep 2023 10:49:59 -0500 Subject: [PATCH 1/2] Check if requestAnimationFrame is defined in shouldUpdate --- src/setRafTimeout.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setRafTimeout.js b/src/setRafTimeout.js index 9560416..966c886 100644 --- a/src/setRafTimeout.js +++ b/src/setRafTimeout.js @@ -10,7 +10,7 @@ export default function setRafTimeout(callback, timeout = 0) { callback(now); currTime = -1; } else { - requestAnimationFrame(shouldUpdate); + if (typeof requestAnimationFrame !== 'undefined') requestAnimationFrame(shouldUpdate); } }; From c3fdcb9ca3f1aa5ec421329832fde2603eeb5b15 Mon Sep 17 00:00:00 2001 From: Brandon Ly Date: Sun, 24 Sep 2023 12:09:53 -0500 Subject: [PATCH 2/2] Small refactor to make eslint happy --- src/setRafTimeout.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/setRafTimeout.js b/src/setRafTimeout.js index 966c886..d5dc766 100644 --- a/src/setRafTimeout.js +++ b/src/setRafTimeout.js @@ -1,3 +1,7 @@ +function safeRequestAnimationFrame(callback) { + if (typeof requestAnimationFrame !== 'undefined') requestAnimationFrame(callback); +} + export default function setRafTimeout(callback, timeout = 0) { let currTime = -1; @@ -10,7 +14,7 @@ export default function setRafTimeout(callback, timeout = 0) { callback(now); currTime = -1; } else { - if (typeof requestAnimationFrame !== 'undefined') requestAnimationFrame(shouldUpdate); + safeRequestAnimationFrame(shouldUpdate); } };