Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: use-isomorphic-layout-effect (#29762)

Alaister Youngb04dbf98762e
diff --git a/apps/studio/hooks/misc/useSynchronizedAnimation.ts b/apps/studio/hooks/misc/useSynchronizedAnimation.ts
index 90258ed0c85..756a3ba62af 100644
--- a/apps/studio/hooks/misc/useSynchronizedAnimation.ts
+++ b/apps/studio/hooks/misc/useSynchronizedAnimation.ts
@@ -1,4 +1,5 @@
-import { useLayoutEffect, useRef } from 'react'
+import { useIsomorphicLayoutEffect } from 'common'
+import { useRef } from 'react'
// Source: https://youtu.be/3kDVachh-BM
@@ -7,7 +8,7 @@ let stashedTime: number | null = null
export function useSynchronizedAnimation<T>(name: string) {
const ref = useRef<T>(null)
- useLayoutEffect(() => {
+ useIsomorphicLayoutEffect(() => {
const animations = document
.getAnimations()
.filter(
diff --git a/packages/common/hooks/index.ts b/packages/common/hooks/index.ts
index b94155dac83..7953fdbf4e3 100644
--- a/packages/common/hooks/index.ts
+++ b/packages/common/hooks/index.ts
@@ -4,6 +4,7 @@ export * from './useCopy'
export * from './useDebounce'
export * from './useDocsSearch'
export * from './useDragToClose'
+export * from './useIsomorphicLayoutEffect'
export * from './useParams'
export * from './useSearchParamsShallow'
export * from './useTelemetryProps'
diff --git a/packages/common/hooks/useIsomorphicLayoutEffect.tsx b/packages/common/hooks/useIsomorphicLayoutEffect.tsx
new file mode 100644
index 00000000000..39a66ae0b8f
--- /dev/null
+++ b/packages/common/hooks/useIsomorphicLayoutEffect.tsx
@@ -0,0 +1,4 @@
+import { useEffect, useLayoutEffect } from 'react'
+
+export const useIsomorphicLayoutEffect =
+ typeof document !== 'undefined' ? useLayoutEffect : useEffect