mirror of
https://github.com/baptisteArno/typebot.io.git
synced 2026-06-22 21:06:40 +08:00
💚 (lp) Fix window is not defined error from embed bubble loading
This commit is contained in:
parent
8d7163dd89
commit
ba5dafbb94
13
apps/landing-page/app/components/ClientOnly.tsx
Normal file
13
apps/landing-page/app/components/ClientOnly.tsx
Normal file
@ -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) => (
|
||||
<Suspense fallback={fallback}>{useHydrated() ? children : fallback}</Suspense>
|
||||
);
|
||||
@ -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 = () => (
|
||||
<Suspense fallback={<div className="size-12" />}>
|
||||
<ClientOnly fallback={<div className="size-12" />}>
|
||||
<Bubble
|
||||
typebot="typebot-demo"
|
||||
theme={{
|
||||
@ -15,5 +16,5 @@ export const TypebotBubble = () => (
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Suspense>
|
||||
</ClientOnly>
|
||||
);
|
||||
|
||||
13
apps/landing-page/app/hooks/useHydrated.ts
Normal file
13
apps/landing-page/app/hooks/useHydrated.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { useSyncExternalStore } from "react";
|
||||
|
||||
function subscribe() {
|
||||
return () => {};
|
||||
}
|
||||
|
||||
export function useHydrated() {
|
||||
return useSyncExternalStore(
|
||||
subscribe,
|
||||
() => true,
|
||||
() => false,
|
||||
);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user