Wrap useSuspense with NoSSR (#8079)

pull/8234/head
Alex van Andel 2023-04-11 18:19:27 +02:00 committed by GitHub
parent ae8706316f
commit 98cf29f655
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 4 deletions

View File

@ -0,0 +1,20 @@
import { useState, useEffect } from "react";
interface Props {
children: React.ReactNode; // React.ReactNode
fallback?: JSX.Element | null; // JSX.Element
}
const NoSSR = ({ children, fallback = null }: Props) => {
const [mounted, setMounted] = useState(false);
useEffect(() => setMounted(true), []);
if (!mounted) {
return fallback;
}
return <>{children}</>;
};
export default NoSSR;

View File

@ -1,5 +1,6 @@
import { Suspense } from "react"; import { Suspense } from "react";
import NoSSR from "@calcom/core/components/NoSSR";
import { Meta } from "@calcom/ui"; import { Meta } from "@calcom/ui";
import { FiLoader } from "@calcom/ui/components/icon"; import { FiLoader } from "@calcom/ui/components/icon";
@ -9,9 +10,11 @@ export const FlagListingView = () => {
return ( return (
<> <>
<Meta title="Feature Flags" description="Here you can toggle your Cal.com instance features." /> <Meta title="Feature Flags" description="Here you can toggle your Cal.com instance features." />
<Suspense fallback={<FiLoader />}> <NoSSR>
<FlagAdminList /> <Suspense fallback={<FiLoader />}>
</Suspense> <FlagAdminList />
</Suspense>
</NoSSR>
</> </>
); );
}; };

View File

@ -23,7 +23,7 @@ export const trpc = createTRPCNext<AppRouter, NextPageContext, "ExperimentalSusp
? "/api/trpc" ? "/api/trpc"
: process.env.VERCEL_URL : process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}/api/trpc` ? `https://${process.env.VERCEL_URL}/api/trpc`
: `http://${process.env.NEXT_PUBLIC_WEBAPP_URL}/api/trpc`; : `${process.env.NEXT_PUBLIC_WEBAPP_URL}/api/trpc`;
/** /**
* If you want to use SSR, you need to use the server's full URL * If you want to use SSR, you need to use the server's full URL