From 26cdb6521f415fec05fe3d4d2193e0e33c3b4b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efra=C3=ADn=20Roch=C3=ADn?= Date: Tue, 18 Apr 2023 11:45:32 -0700 Subject: [PATCH] perf: Adds PageWrapper to pages (#8344) * Adds PageWrapper to pages * Add missing PageWrapper --------- Co-authored-by: Keith Williams Co-authored-by: Hariom Balhara --- apps/web/components/PageWrapper.tsx | 99 +++++++++++++++++++ apps/web/lib/app-providers.tsx | 1 + apps/web/pages/404.tsx | 4 + apps/web/pages/500.tsx | 4 + apps/web/pages/[user].tsx | 3 + apps/web/pages/[user]/[type].tsx | 2 + apps/web/pages/[user]/book.tsx | 2 + apps/web/pages/_app.tsx | 77 +-------------- apps/web/pages/apps/[slug]/[...pages].tsx | 7 +- apps/web/pages/apps/[slug]/index.tsx | 3 + apps/web/pages/apps/[slug]/setup.tsx | 4 + apps/web/pages/apps/categories/[category].tsx | 4 + apps/web/pages/apps/categories/index.tsx | 4 + apps/web/pages/apps/index.tsx | 3 + apps/web/pages/apps/installed/[category].tsx | 3 + apps/web/pages/auth/error.tsx | 3 + apps/web/pages/auth/forgot-password/[id].tsx | 3 +- apps/web/pages/auth/forgot-password/index.tsx | 2 + apps/web/pages/auth/login.tsx | 2 + apps/web/pages/auth/logout.tsx | 3 +- apps/web/pages/auth/saml-idp.tsx | 3 + apps/web/pages/auth/setup/index.tsx | 3 +- apps/web/pages/auth/signin.tsx | 4 + apps/web/pages/auth/sso/[provider].tsx | 4 + apps/web/pages/auth/sso/direct.tsx | 4 + apps/web/pages/auth/verify.tsx | 3 + apps/web/pages/availability/[schedule].tsx | 3 + apps/web/pages/availability/index.tsx | 3 + apps/web/pages/availability/troubleshoot.tsx | 3 + apps/web/pages/booking/[uid].tsx | 2 + apps/web/pages/bookings/[status].tsx | 3 + apps/web/pages/d/[link]/[slug].tsx | 2 + apps/web/pages/d/[link]/book.tsx | 2 + apps/web/pages/event-types/[type]/index.tsx | 3 + apps/web/pages/event-types/index.tsx | 3 + .../web/pages/getting-started/[[...step]].tsx | 2 + apps/web/pages/insights/index.tsx | 4 + apps/web/pages/maintenance.tsx | 4 + apps/web/pages/more.tsx | 3 + apps/web/pages/payment/[uid].tsx | 4 +- .../pages/settings/admin/apps/[category].tsx | 2 + apps/web/pages/settings/admin/flags.tsx | 2 + .../pages/settings/admin/impersonation.tsx | 2 + apps/web/pages/settings/admin/index.tsx | 2 + .../pages/settings/admin/users/[id]/edit.tsx | 10 +- apps/web/pages/settings/admin/users/add.tsx | 10 +- apps/web/pages/settings/admin/users/index.tsx | 10 +- apps/web/pages/settings/billing/index.tsx | 3 + .../web/pages/settings/developer/api-keys.tsx | 3 + .../developer/webhooks/[id]/index.tsx | 10 +- .../settings/developer/webhooks/index.tsx | 10 +- .../pages/settings/developer/webhooks/new.tsx | 10 +- .../pages/settings/my-account/appearance.tsx | 3 + .../pages/settings/my-account/calendars.tsx | 2 + .../settings/my-account/conferencing.tsx | 2 + .../web/pages/settings/my-account/general.tsx | 3 + .../web/pages/settings/my-account/profile.tsx | 2 + .../pages/settings/security/impersonation.tsx | 3 + apps/web/pages/settings/security/password.tsx | 3 + apps/web/pages/settings/security/sso.tsx | 10 +- .../settings/security/two-factor-auth.tsx | 2 + .../pages/settings/teams/[id]/appearance.tsx | 10 +- .../web/pages/settings/teams/[id]/billing.tsx | 10 +- .../web/pages/settings/teams/[id]/members.tsx | 10 +- .../settings/teams/[id]/onboard-members.tsx | 3 + .../web/pages/settings/teams/[id]/profile.tsx | 10 +- apps/web/pages/settings/teams/[id]/sso.tsx | 10 +- apps/web/pages/settings/teams/index.ts | 10 +- apps/web/pages/settings/teams/new/index.tsx | 2 + apps/web/pages/signup.tsx | 3 + apps/web/pages/team/[slug].tsx | 2 + apps/web/pages/team/[slug]/[type].tsx | 2 + apps/web/pages/team/[slug]/book.tsx | 2 + apps/web/pages/teams/index.tsx | 3 + apps/web/pages/video/[uid].tsx | 4 + apps/web/pages/video/meeting-ended/[uid].tsx | 4 + .../pages/video/meeting-not-started/[uid].tsx | 4 + apps/web/pages/video/no-meeting-found.tsx | 4 + apps/web/pages/workflows/[workflow].tsx | 10 +- apps/web/pages/workflows/index.tsx | 10 +- 80 files changed, 418 insertions(+), 94 deletions(-) create mode 100644 apps/web/components/PageWrapper.tsx diff --git a/apps/web/components/PageWrapper.tsx b/apps/web/components/PageWrapper.tsx new file mode 100644 index 0000000000..1b9fabb052 --- /dev/null +++ b/apps/web/components/PageWrapper.tsx @@ -0,0 +1,99 @@ +import { DefaultSeo } from "next-seo"; +import { Inter } from "next/font/google"; +import localFont from "next/font/local"; +import Script from "next/script"; + +import "@calcom/embed-core/src/embed-iframe"; +import { useEmbedUiConfig } from "@calcom/embed-core/src/embed-iframe"; +import LicenseRequired from "@calcom/features/ee/common/components/LicenseRequired"; + +import type { AppProps } from "@lib/app-providers"; +import AppProviders from "@lib/app-providers"; +import { seoConfig } from "@lib/config/next-seo.config"; + +import I18nLanguageHandler from "@components/I18nLanguageHandler"; + +export interface CalPageWrapper { + (props?: any): JSX.Element; + PageWrapper?: AppProps["Component"]["PageWrapper"]; +} + +const interFont = Inter({ subsets: ["latin"], variable: "--font-inter", preload: true, display: "swap" }); +const calFont = localFont({ + src: "../fonts/CalSans-SemiBold.woff2", + variable: "--font-cal", + preload: true, + display: "swap", +}); + +function PageWrapper(props: AppProps) { + const { Component, pageProps, err, router } = props; + let pageStatus = "200"; + const { cssVarsPerTheme } = useEmbedUiConfig(); + const cssVarsStyle = []; + if (cssVarsPerTheme) { + for (const [themeName, cssVars] of Object.entries(cssVarsPerTheme)) { + cssVarsStyle.push(`.${themeName} {`); + for (const [cssVarName, value] of Object.entries(cssVars)) { + cssVarsStyle.push(`--${cssVarName}: ${value};`); + } + cssVarsStyle.push(`}`); + } + } + + if (router.pathname === "/404") { + pageStatus = "404"; + } else if (router.pathname === "/500") { + pageStatus = "500"; + } + + // 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, + }, + }; + // Use the layout defined at the page level, if available + const getLayout = Component.getLayout ?? ((page) => page); + return ( + + + +