diff --git a/src/utils/env.ts b/src/utils/env.ts index 3389500a0..3912aa311 100644 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -1,11 +1,11 @@ import { useEffect, useLayoutEffect } from 'react' -import { hasWindow } from './helper' +import { hasRequestAnimationFrame, hasWindow } from './helper' export const IS_SERVER = !hasWindow() || 'Deno' in window // Polyfill requestAnimationFrame export const rAF = (f: (...args: any[]) => void) => - hasWindow() ? window['requestAnimationFrame'](f) : setTimeout(f, 1) + hasRequestAnimationFrame() ? window['requestAnimationFrame'](f) : setTimeout(f, 1) // React currently throws a warning when using useLayoutEffect on the server. // To get around it, we can conditionally useEffect on the server (no-op) and diff --git a/src/utils/helper.ts b/src/utils/helper.ts index f153ef448..ab42ce1d4 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -15,3 +15,4 @@ export const mergeObjects = (a: any, b: any) => OBJECT.assign({}, a, b) const STR_UNDEFINED = 'undefined' export const hasWindow = () => typeof window != STR_UNDEFINED export const hasDocument = () => typeof document != STR_UNDEFINED +export const hasRequestAnimationFrame = () => (hasWindow() && (typeof window['requestAnimationFrame'] != STR_UNDEFINED)) \ No newline at end of file