perf: run ssrInit() at root layout (#19460)
* wip * remove ssrInit unneeded * refactor * revert unneeded changes * update booking-page-wrapper layout
This commit is contained in:
1 parent
307b2946a2
commit
6ea879f265
7 files changed
+25
-38
No files matched your search
@@ -1,24 +1,13 @@
|
||||
import { cookies, headers } from "next/headers";
|
||||
|
||||
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
|
||||
import { headers } from "next/headers";
|
||||
|
||||
import PageWrapper from "@components/PageWrapperAppDir";
|
||||
|
||||
import { ssrInit } from "@server/lib/ssr";
|
||||
|
||||
export default async function BookingPageWrapperLayout({ children }: { children: React.ReactNode }) {
|
||||
const h = headers();
|
||||
const nonce = h.get("x-nonce") ?? undefined;
|
||||
const context = buildLegacyCtx(h, cookies(), {}, {});
|
||||
const ssr = await ssrInit(context);
|
||||
|
||||
return (
|
||||
<PageWrapper
|
||||
isBookingPage={true}
|
||||
requiresLicense={false}
|
||||
nonce={nonce}
|
||||
themeBasis={null}
|
||||
dehydratedState={ssr.dehydrate()}>
|
||||
<PageWrapper isBookingPage={true} requiresLicense={false} nonce={nonce} themeBasis={null}>
|
||||
{children}
|
||||
</PageWrapper>
|
||||
);
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
import { cookies, headers } from "next/headers";
|
||||
|
||||
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
|
||||
import { headers } from "next/headers";
|
||||
|
||||
import PageWrapper from "@components/PageWrapperAppDir";
|
||||
|
||||
import { ssrInit } from "@server/lib/ssr";
|
||||
|
||||
export default async function PageWrapperLayout({ children }: { children: React.ReactNode }) {
|
||||
const h = headers();
|
||||
const nonce = h.get("x-nonce") ?? undefined;
|
||||
|
||||
const context = buildLegacyCtx(headers(), cookies(), {}, {});
|
||||
const ssr = await ssrInit(context);
|
||||
|
||||
return (
|
||||
<PageWrapper requiresLicense={false} nonce={nonce} themeBasis={null} dehydratedState={ssr.dehydrate()}>
|
||||
<PageWrapper requiresLicense={false} nonce={nonce} themeBasis={null}>
|
||||
{children}
|
||||
</PageWrapper>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { type DehydratedState, QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { HydrateClient } from "app/_trpc/HydrateClient";
|
||||
import { trpc } from "app/_trpc/client";
|
||||
import { useState } from "react";
|
||||
import superjson from "superjson";
|
||||
@@ -42,9 +43,10 @@ const isTRPCClientError = (cause: unknown): cause is TRPCClientError<AppRouter>
|
||||
|
||||
type Props = {
|
||||
children: React.ReactNode;
|
||||
dehydratedState: DehydratedState;
|
||||
};
|
||||
|
||||
export const TrpcProvider = ({ children }: Props) => {
|
||||
export const TrpcProvider = ({ children, dehydratedState }: Props) => {
|
||||
const [queryClient] = useState(
|
||||
() =>
|
||||
new QueryClient({
|
||||
@@ -126,7 +128,9 @@ export const TrpcProvider = ({ children }: Props) => {
|
||||
|
||||
return (
|
||||
<trpc.Provider client={trpcClient} queryClient={queryClient}>
|
||||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<HydrateClient state={dehydratedState}>{children}</HydrateClient>
|
||||
</QueryClientProvider>
|
||||
</trpc.Provider>
|
||||
);
|
||||
};
|
||||
@@ -7,8 +7,11 @@ import React from "react";
|
||||
import { getLocale } from "@calcom/features/auth/lib/getLocale";
|
||||
import { IconSprites } from "@calcom/ui";
|
||||
|
||||
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
|
||||
import { prepareRootMetadata } from "@lib/metadata";
|
||||
|
||||
import { ssrInit } from "@server/lib/ssr";
|
||||
|
||||
import "../styles/globals.css";
|
||||
import { SpeculationRules } from "./SpeculationRules";
|
||||
import { Providers } from "./providers";
|
||||
@@ -56,6 +59,7 @@ export default async function RootLayout({ children }: { children: React.ReactNo
|
||||
? getFallbackProps()
|
||||
: await getInitialProps(fullUrl);
|
||||
|
||||
const ssr = await ssrInit(buildLegacyCtx(h, cookies(), {}, {}));
|
||||
return (
|
||||
<html
|
||||
lang={locale}
|
||||
@@ -159,7 +163,7 @@ export default async function RootLayout({ children }: { children: React.ReactNo
|
||||
"/insights",
|
||||
]}
|
||||
/>
|
||||
<Providers>{children}</Providers>
|
||||
<Providers dehydratedState={ssr.dehydrate()}>{children}</Providers>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { type DehydratedState } from "@tanstack/react-query";
|
||||
import { TrpcProvider } from "app/_trpc/trpc-provider";
|
||||
import { SessionProvider } from "next-auth/react";
|
||||
import CacheProvider from "react-inlinesvg/provider";
|
||||
@@ -7,12 +8,16 @@ import CacheProvider from "react-inlinesvg/provider";
|
||||
import useIsBookingPage from "@lib/hooks/useIsBookingPage";
|
||||
import PlainChat from "@lib/plain/dynamicProvider";
|
||||
|
||||
export function Providers({ children }: { children: React.ReactNode }) {
|
||||
type ProvidersProps = {
|
||||
children: React.ReactNode;
|
||||
dehydratedState: DehydratedState;
|
||||
};
|
||||
export function Providers({ children, dehydratedState }: ProvidersProps) {
|
||||
const isBookingPage = useIsBookingPage();
|
||||
|
||||
return (
|
||||
<SessionProvider>
|
||||
<TrpcProvider>
|
||||
<TrpcProvider dehydratedState={dehydratedState}>
|
||||
{!isBookingPage ? <PlainChat /> : null}
|
||||
{/* @ts-expect-error FIXME remove this comment when upgrading typescript to v5 */}
|
||||
<CacheProvider>{children}</CacheProvider>
|
||||
|
||||
Reference in new issue
Block a user