2021-08-27 12:35:20 +00:00
import { DefaultSeo } from "next-seo" ;
2022-03-24 16:51:37 +00:00
import Head from "next/head" ;
2022-12-08 23:39:15 +00:00
import Script from "next/script" ;
2021-10-07 15:43:20 +00:00
import superjson from "superjson" ;
2021-09-22 19:52:38 +00:00
2022-03-31 08:45:47 +00:00
import "@calcom/embed-core/src/embed-iframe" ;
2022-07-28 19:58:26 +00:00
import LicenseRequired from "@calcom/features/ee/common/components/LicenseRequired" ;
2022-07-22 17:27:06 +00:00
import { httpBatchLink } from "@calcom/trpc/client/links/httpBatchLink" ;
import { httpLink } from "@calcom/trpc/client/links/httpLink" ;
import { loggerLink } from "@calcom/trpc/client/links/loggerLink" ;
import { splitLink } from "@calcom/trpc/client/links/splitLink" ;
import { withTRPC } from "@calcom/trpc/next" ;
import type { TRPCClientErrorLike } from "@calcom/trpc/react" ;
import { Maybe } from "@calcom/trpc/server" ;
import type { AppRouter } from "@calcom/trpc/server/routers/_app" ;
2022-03-31 08:45:47 +00:00
2021-10-20 16:00:11 +00:00
import AppProviders , { AppProps } from "@lib/app-providers" ;
2021-08-27 12:35:20 +00:00
import { seoConfig } from "@lib/config/next-seo.config" ;
2021-03-10 10:02:39 +00:00
2021-10-12 13:11:33 +00:00
import I18nLanguageHandler from "@components/I18nLanguageHandler" ;
2021-09-22 19:52:38 +00:00
import "../styles/globals.css" ;
2021-09-27 14:47:55 +00:00
function MyApp ( props : AppProps ) {
2022-04-08 05:33:24 +00:00
const { Component , pageProps , err , router } = props ;
let pageStatus = "200" ;
if ( router . pathname === "/404" ) {
pageStatus = "404" ;
} else if ( router . pathname === "/500" ) {
pageStatus = "500" ;
}
2023-02-06 22:50:08 +00:00
// On client side don't let nonce creep into DOM
// It also avoids hydration warning that says that Client has the nonce value but server has "" because browser removes nonce attributes before DOM is built
// See https://github.com/kentcdodds/nonce-hydration-issues
// Set "" only if server had it set otherwise keep it undefined because server has to match with client to avoid hydration error
const nonce = typeof window !== "undefined" ? ( pageProps . nonce ? "" : undefined ) : pageProps . nonce ;
const providerProps = {
. . . props ,
pageProps : {
. . . props . pageProps ,
nonce ,
} ,
} ;
2022-08-09 09:21:15 +00:00
// Use the layout defined at the page level, if available
const getLayout = Component . getLayout ? ? ( ( page ) = > page ) ;
2021-03-24 15:03:04 +00:00
return (
2023-02-06 22:50:08 +00:00
< AppProviders { ...providerProps } >
2022-07-28 19:58:26 +00:00
< DefaultSeo { ...seoConfig.defaultNextSeo } / >
< I18nLanguageHandler / >
2022-12-08 23:39:15 +00:00
< Script
2023-02-06 22:50:08 +00:00
nonce = { nonce }
2022-12-08 23:39:15 +00:00
id = "page-status"
dangerouslySetInnerHTML = { { __html : ` window.CalComPageStatus = ' ${ pageStatus } ' ` } }
/ >
2022-07-28 19:58:26 +00:00
< Head >
< meta name = "viewport" content = "width=device-width, initial-scale=1, maximum-scale=1" / >
< / Head >
2022-08-09 09:21:15 +00:00
{ getLayout (
Component . requiresLicense ? (
< LicenseRequired >
< Component { ...pageProps } err = { err } / >
< / LicenseRequired >
) : (
2022-07-28 19:58:26 +00:00
< Component { ...pageProps } err = { err } / >
2022-09-02 19:00:41 +00:00
) ,
router
2022-07-28 19:58:26 +00:00
) }
< / AppProviders >
2021-04-11 17:12:18 +00:00
) ;
2021-03-10 10:02:39 +00:00
}
2021-10-01 14:33:14 +00:00
export default withTRPC < AppRouter > ( {
2021-09-30 12:28:30 +00:00
config() {
2022-06-19 15:02:00 +00:00
const url =
typeof window !== "undefined"
? "/api/trpc"
: process . env . VERCEL_URL
? ` https:// ${ process . env . VERCEL_URL } /api/trpc `
: ` http:// ${ process . env . NEXT_PUBLIC_WEBAPP_URL } /api/trpc ` ;
2021-09-30 12:28:30 +00:00
/ * *
* If you want to use SSR , you need to use the server ' s full URL
* @link https : //trpc.io/docs/ssr
* /
return {
/ * *
* @link https : //trpc.io/docs/links
* /
links : [
// adds pretty logs to your console in development and logs errors in production
loggerLink ( {
enabled : ( opts ) = >
2022-02-23 16:37:41 +00:00
! ! process . env . NEXT_PUBLIC_DEBUG || ( opts . direction === "down" && opts . result instanceof Error ) ,
2021-09-30 12:28:30 +00:00
} ) ,
2022-06-19 15:02:00 +00:00
splitLink ( {
// check for context property `skipBatch`
2022-06-29 16:50:32 +00:00
condition : ( op ) = > {
2022-07-18 18:59:51 +00:00
return op . context . skipBatch === true ;
2022-06-29 16:50:32 +00:00
} ,
2022-06-19 15:02:00 +00:00
// when condition is true, use normal request
true : httpLink ( { url } ) ,
// when condition is false, use batching
false : httpBatchLink ( {
url ,
/** @link https://github.com/trpc/trpc/issues/2008 */
// maxBatchSize: 7
} ) ,
2021-09-30 12:28:30 +00:00
} ) ,
] ,
/ * *
* @link https : //react-query.tanstack.com/reference/QueryClient
* /
2021-10-01 14:33:14 +00:00
queryClientConfig : {
defaultOptions : {
queries : {
/ * *
* 1 s should be enough to just keep identical query waterfalls low
* @example if one page components uses a query that is also used further down the tree
* /
staleTime : 1000 ,
/ * *
* Retry ` useQuery() ` calls depending on this function
* /
retry ( failureCount , _err ) {
const err = _err as never as Maybe < TRPCClientErrorLike < AppRouter > > ;
const code = err ? . data ? . code ;
if ( code === "BAD_REQUEST" || code === "FORBIDDEN" || code === "UNAUTHORIZED" ) {
// if input data is wrong or you're not authorized there's no point retrying a query
return false ;
}
const MAX_QUERY_RETRIES = 3 ;
return failureCount < MAX_QUERY_RETRIES ;
} ,
} ,
} ,
} ,
2021-10-07 15:43:20 +00:00
/ * *
* @link https : //trpc.io/docs/data-transformers
* /
transformer : superjson ,
2021-09-30 12:28:30 +00:00
} ;
} ,
/ * *
* @link https : //trpc.io/docs/ssr
* /
ssr : false ,
2021-10-14 10:57:49 +00:00
} ) ( MyApp ) ;