From 775cc4d649fa8826190d600af333a5e3863e4384 Mon Sep 17 00:00:00 2001 From: Trezy Date: Sun, 28 Jul 2024 22:55:42 -0500 Subject: [PATCH] fix(useTick): fix `useTick` not firing in SSR envs `useTick` was failing to fire on the first tick in server rendered environments (such as Next.js applications) because the `useEffect` wasn't being triggered. This is fixed by switching to use `useIsomorphicLayoutEffect` instead.` fixes #506 --- src/hooks/useTick.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hooks/useTick.ts b/src/hooks/useTick.ts index eba9156d..28d955b6 100644 --- a/src/hooks/useTick.ts +++ b/src/hooks/useTick.ts @@ -1,6 +1,6 @@ -import { useEffect } from 'react'; import { invariant } from '../helpers/invariant.ts'; import { useApp } from './useApp.ts'; +import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect.ts'; import type { TickerCallback } from 'pixi.js'; import type { TickCallbackOptions } from '../typedefs/TickCallbackOptions.ts'; @@ -35,7 +35,7 @@ function useTick( invariant(typeof callback === 'function', '`useTick` needs a callback function.'); // eslint-disable-next-line consistent-return - useEffect(() => + useIsomorphicLayoutEffect(() => { const ticker = app?.ticker;