diff --git a/src/hooks.ts b/src/hooks.ts index c68eb15..7f4f2ac 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -7,10 +7,17 @@ import { buildGraph, classExtends } from './utils' /** * An SSR-friendly useLayoutEffect. + * + * 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 + * useLayoutEffect elsewhere. + * + * @see https://github.com/facebook/react/issues/14927 */ -const isSSR = - typeof window === 'undefined' || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent) -export const useIsomorphicLayoutEffect = isSSR ? React.useEffect : React.useLayoutEffect +export const useIsomorphicLayoutEffect = + typeof window !== 'undefined' && (window.document?.createElement || window.navigator?.product === 'ReactNative') + ? React.useLayoutEffect + : React.useEffect /** * Internal OGL context.