fix: client locale inference (#10850)
This commit is contained in:
1 parent
bbad0fbc18
commit
6743aa4609
16 files changed
+102
-127
No files matched your search
@@ -2,6 +2,7 @@ import type { GetStaticPropsContext } from "next";
|
||||
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
|
||||
import superjson from "superjson";
|
||||
|
||||
import { CALCOM_VERSION } from "@calcom/lib/constants";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { createProxySSGHelpers } from "@calcom/trpc/react/ssg";
|
||||
import { appRouter } from "@calcom/trpc/server/routers/_app";
|
||||
@@ -9,10 +10,6 @@ import { appRouter } from "@calcom/trpc/server/routers/_app";
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const { i18n } = require("@calcom/config/next-i18next.config");
|
||||
|
||||
// TODO: Consolidate this constant
|
||||
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||
const CalComVersion = process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA || "NA";
|
||||
|
||||
/**
|
||||
* Initialize static site rendering tRPC helpers.
|
||||
* Provides a method to prefetch tRPC-queries in a `getStaticProps`-function.
|
||||
@@ -41,7 +38,7 @@ export async function ssgInit<TParams extends { locale?: string }>(opts: GetStat
|
||||
});
|
||||
|
||||
// always preload i18n
|
||||
await ssg.viewer.public.i18n.fetch({ locale, CalComVersion });
|
||||
await ssg.viewer.public.i18n.fetch({ locale, CalComVersion: CALCOM_VERSION });
|
||||
|
||||
return ssg;
|
||||
}
|
||||
+13
-15
@@ -2,15 +2,12 @@ import type { GetServerSidePropsContext } from "next";
|
||||
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
|
||||
import superjson from "superjson";
|
||||
|
||||
import { getLocaleFromHeaders } from "@calcom/lib/i18n";
|
||||
import { CALCOM_VERSION } from "@calcom/lib/constants";
|
||||
import { getLocaleFromRequest } from "@calcom/lib/i18n";
|
||||
import { createProxySSGHelpers } from "@calcom/trpc/react/ssg";
|
||||
import { createContext } from "@calcom/trpc/server/createContext";
|
||||
import { appRouter } from "@calcom/trpc/server/routers/_app";
|
||||
|
||||
// TODO: Consolidate this constant
|
||||
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||
const CalComVersion = process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA || "NA";
|
||||
|
||||
/**
|
||||
* Initialize server-side rendering tRPC helpers.
|
||||
* Provides a method to prefetch tRPC-queries in a `getServerSideProps`-function.
|
||||
@@ -19,8 +16,8 @@ const CalComVersion = process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA || "NA";
|
||||
*/
|
||||
export async function ssrInit(context: GetServerSidePropsContext) {
|
||||
const ctx = await createContext(context);
|
||||
const locale = getLocaleFromHeaders(context.req);
|
||||
const i18n = await serverSideTranslations(getLocaleFromHeaders(context.req), ["common", "vital"]);
|
||||
const locale = await getLocaleFromRequest(context.req);
|
||||
const i18n = await serverSideTranslations(locale, ["common", "vital"]);
|
||||
|
||||
const ssr = createProxySSGHelpers({
|
||||
router: appRouter,
|
||||
@@ -28,14 +25,15 @@ export async function ssrInit(context: GetServerSidePropsContext) {
|
||||
ctx: { ...ctx, locale, i18n },
|
||||
});
|
||||
|
||||
// always preload "viewer.public.i18n"
|
||||
await ssr.viewer.public.i18n.fetch({ locale, CalComVersion });
|
||||
// So feature flags are available on first render
|
||||
await ssr.viewer.features.map.prefetch();
|
||||
// Provides a better UX to the users who have already upgraded.
|
||||
await ssr.viewer.teams.hasTeamPlan.prefetch();
|
||||
|
||||
await ssr.viewer.public.session.prefetch();
|
||||
await Promise.allSettled([
|
||||
// always preload "viewer.public.i18n"
|
||||
ssr.viewer.public.i18n.prefetch({ locale, CalComVersion: CALCOM_VERSION }),
|
||||
// So feature flags are available on first render
|
||||
ssr.viewer.features.map.prefetch(),
|
||||
// Provides a better UX to the users who have already upgraded.
|
||||
ssr.viewer.teams.hasTeamPlan.prefetch(),
|
||||
ssr.viewer.public.session.prefetch(),
|
||||
]);
|
||||
|
||||
return ssr;
|
||||
}
|
||||
Reference in new issue
Block a user