fix i18n flicker on booking pages (#1013)

This commit is contained in:
Alex Johansson authored and GitHub committed 2021-10-20 16:00:11 +00:00
1 parent b8e8319b23
commit c28d800aa9
8 files changed
+76 -44

No files matched your search

+20 -6
View File
@@ -1,7 +1,7 @@
import { IdProvider } from "@radix-ui/react-id";
import { Provider } from "next-auth/client";
import { appWithTranslation } from "next-i18next";
import { AppProps } from "next/dist/shared/lib/router/router";
import type { AppProps as NextAppProps } from "next/app";
import React, { ComponentProps, ReactNode } from "react";
import DynamicIntercomProvider from "@ee/lib/intercom/providerDynamic";
@@ -12,24 +12,38 @@ import { trpc } from "./trpc";
const I18nextAdapter = appWithTranslation(({ children }: { children?: ReactNode }) => <>{children}</>);
const CustomI18nextProvider = (props: { children: ReactNode }) => {
// Workaround for https://github.com/vercel/next.js/issues/8592
export type AppProps = NextAppProps & {
/** Will be defined only is there was an error */
err?: Error;
};
type AppPropsWithChildren = AppProps & {
children: ReactNode;
};
const CustomI18nextProvider = (props: AppPropsWithChildren) => {
const { i18n, locale } = trpc.useQuery(["viewer.i18n"]).data ?? {};
const passedProps = {
...props,
pageProps: { ...i18n },
router: { locale },
pageProps: {
...props.pageProps,
...i18n,
},
router: locale ? { locale } : props.router,
} as unknown as ComponentProps<typeof I18nextAdapter>;
return <I18nextAdapter {...passedProps} />;
};
const AppProviders = (props: AppProps) => {
const AppProviders = (props: AppPropsWithChildren) => {
const session = trpc.useQuery(["viewer.session"]).data;
return (
<TelemetryProvider value={createTelemetryClient()}>
<IdProvider>
<DynamicIntercomProvider>
<Provider session={session || undefined}>
<CustomI18nextProvider>{props.children}</CustomI18nextProvider>
<CustomI18nextProvider {...props}>{props.children}</CustomI18nextProvider>
</Provider>
</DynamicIntercomProvider>
</IdProvider>