diff --git a/apps/landing-page/app/components/ClientOnly.tsx b/apps/landing-page/app/components/ClientOnly.tsx new file mode 100644 index 000000000..a3bae4885 --- /dev/null +++ b/apps/landing-page/app/components/ClientOnly.tsx @@ -0,0 +1,13 @@ +// Copied from https://github.com/sergiodxa/remix-utils/blob/main/src/react/use-hydrated.ts + +import { useHydrated } from "@/hooks/useHydrated"; +import { type ReactNode, Suspense } from "react"; + +type Props = { + children: ReactNode; + fallback?: ReactNode; +}; + +export const ClientOnly = ({ children, fallback = null }: Props) => ( + {useHydrated() ? children : fallback} +); diff --git a/apps/landing-page/app/components/TypebotBubble.tsx b/apps/landing-page/app/components/TypebotBubble.tsx index 89a62afc8..cc2b4e24c 100644 --- a/apps/landing-page/app/components/TypebotBubble.tsx +++ b/apps/landing-page/app/components/TypebotBubble.tsx @@ -1,11 +1,12 @@ -import { Suspense, lazy } from "react"; +import { lazy } from "react"; +import { ClientOnly } from "./ClientOnly"; export const Bubble = lazy(() => import("@typebot.io/react").then((m) => ({ default: m.Bubble })), ); export const TypebotBubble = () => ( - }> + }> ( }, }} /> - + ); diff --git a/apps/landing-page/app/hooks/useHydrated.ts b/apps/landing-page/app/hooks/useHydrated.ts new file mode 100644 index 000000000..7bf890427 --- /dev/null +++ b/apps/landing-page/app/hooks/useHydrated.ts @@ -0,0 +1,13 @@ +import { useSyncExternalStore } from "react"; + +function subscribe() { + return () => {}; +} + +export function useHydrated() { + return useSyncExternalStore( + subscribe, + () => true, + () => false, + ); +}