2021-10-20 16:00:11 +00:00
|
|
|
import { GetServerSidePropsContext } from "next";
|
|
|
|
import superjson from "superjson";
|
|
|
|
|
2022-07-22 17:27:06 +00:00
|
|
|
import { createSSGHelpers } from "@calcom/trpc/react/ssg";
|
|
|
|
import { createContext } from "@calcom/trpc/server/createContext";
|
|
|
|
import { appRouter } from "@calcom/trpc/server/routers/_app";
|
2021-10-20 16:00:11 +00:00
|
|
|
|
2021-12-14 12:31:54 +00:00
|
|
|
/**
|
|
|
|
* Initialize server-side rendering tRPC helpers.
|
|
|
|
* Provides a method to prefetch tRPC-queries in a `getServerSideProps`-function.
|
|
|
|
* Automatically prefetches i18n based on the passed in `context`-object to prevent i18n-flickering.
|
|
|
|
* Make sure to `return { props: { trpcState: ssr.dehydrate() } }` at the end.
|
|
|
|
*/
|
2021-10-20 16:00:11 +00:00
|
|
|
export async function ssrInit(context: GetServerSidePropsContext) {
|
|
|
|
const ctx = await createContext(context);
|
|
|
|
|
|
|
|
const ssr = createSSGHelpers({
|
|
|
|
router: appRouter,
|
|
|
|
transformer: superjson,
|
|
|
|
ctx,
|
|
|
|
});
|
|
|
|
|
2022-06-19 15:02:00 +00:00
|
|
|
// always preload "viewer.public.i18n"
|
|
|
|
await ssr.fetchQuery("viewer.public.i18n");
|
2021-10-20 16:00:11 +00:00
|
|
|
|
|
|
|
return ssr;
|
|
|
|
}
|