Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: make routes not go through middleware #19311

Closed
wants to merge 18 commits into from
62 changes: 0 additions & 62 deletions apps/web/abTest/middlewareFactory.ts

This file was deleted.

9 changes: 0 additions & 9 deletions apps/web/abTest/utils.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { ShellMainAppDir } from "../ShellMainAppDir";
export const generateMetadata = async () => {
return await _generateMetadata(
(t) => t("availability"),
(t) => t("configure_availability")
(t) => t("configure_availability"),
undefined,
undefined,
"/availability"
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@ import { _generateMetadata, getTranslate } from "app/_utils";
import { redirect } from "next/navigation";
import { z } from "zod";

import { decodeParams } from "@lib/buildLegacyCtx";

import { validStatuses } from "~/bookings/lib/validStatuses";
import BookingsList from "~/bookings/views/bookings-listing-view";

const querySchema = z.object({
status: z.enum(validStatuses),
});

export const generateMetadata = async () =>
export const generateMetadata = async ({ params }: PageProps) =>
await _generateMetadata(
(t) => t("bookings"),
(t) => t("bookings_description")
(t) => t("bookings_description"),
undefined,
undefined,
`/bookings/${decodeParams(params).status}`
);

const Page = async ({ params }: PageProps) => {
const parsed = querySchema.safeParse(params);
const parsed = querySchema.safeParse(decodeParams(params));
if (!parsed.success) {
redirect("/bookings/upcoming");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import EventTypes, { EventTypesCTA } from "~/event-types/views/event-types-listi
export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("event_types_page_title"),
(t) => t("event_types_page_subtitle")
(t) => t("event_types_page_subtitle"),
undefined,
undefined,
"/event-types"
);

const Page = async ({ params, searchParams }: PageProps) => {
Expand Down
5 changes: 4 additions & 1 deletion apps/web/app/(use-page-wrapper)/(main-nav)/teams/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import TeamsView, { TeamsCTA } from "~/teams/teams-view";
export const generateMetadata = async () =>
await _generateMetadata(
(t) => t("teams"),
(t) => t("create_manage_teams_collaborative")
(t) => t("create_manage_teams_collaborative"),
undefined,
undefined,
"/teams"
);

const getData = withAppDirSsr<ClientPageProps>(getServerSideProps);
Expand Down
5 changes: 4 additions & 1 deletion apps/web/app/(use-page-wrapper)/403/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { Button } from "@calcom/ui";
export const generateMetadata = () =>
_generateMetadata(
(t) => `${t("access_denied")} | ${APP_NAME}`,
() => ""
() => "",
undefined,
undefined,
"/403"
);

async function Error403() {
Expand Down
5 changes: 4 additions & 1 deletion apps/web/app/(use-page-wrapper)/500/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import CopyButton from "./copy-button";
export const generateMetadata = () =>
_generateMetadata(
(t) => `${t("something_unexpected_occurred")} | ${APP_NAME}`,
() => ""
() => "",
undefined,
undefined,
"/500"
);

async function Error500({ searchParams }: { searchParams: { error?: string } }) {
Expand Down
6 changes: 4 additions & 2 deletions apps/web/app/(use-page-wrapper)/[user]/[type]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { headers, cookies } from "next/headers";

import { getOrgFullOrigin } from "@calcom/features/ee/organizations/lib/orgDomains";

import { buildLegacyCtx } from "@lib/buildLegacyCtx";
import { buildLegacyCtx, decodeParams } from "@lib/buildLegacyCtx";

import { getServerSideProps } from "@server/lib/[user]/[type]/getServerSideProps";

Expand All @@ -31,12 +31,14 @@ export const generateMetadata = async ({ params, searchParams }: PageProps) => {
})),
],
};
const decodedParams = decodeParams(params);
const metadata = await generateMeetingMetadata(
meeting,
(t) => `${rescheduleUid && !!booking ? t("reschedule") : ""} ${title} | ${profileName}`,
(t) => `${rescheduleUid ? t("reschedule") : ""} ${title}`,
isBrandingHidden,
getOrgFullOrigin(eventData?.entity.orgSlug ?? null)
getOrgFullOrigin(eventData?.entity.orgSlug ?? null),
`/${decodedParams.user}/${decodedParams.type}`
);

return {
Expand Down
6 changes: 4 additions & 2 deletions apps/web/app/(use-page-wrapper)/[user]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { headers, cookies } from "next/headers";

import { getOrgFullOrigin } from "@calcom/features/ee/organizations/lib/orgDomains";

import { buildLegacyCtx } from "@lib/buildLegacyCtx";
import { buildLegacyCtx, decodeParams } from "@lib/buildLegacyCtx";

import { getServerSideProps } from "@server/lib/[user]/getServerSideProps";

Expand All @@ -25,12 +25,14 @@ export const generateMetadata = async ({ params, searchParams }: PageProps) => {
profile: { name: `${profile.name}`, image: profile.image },
users: [{ username: `${profile.username}`, name: `${profile.name}` }],
};

const metadata = await generateMeetingMetadata(
meeting,
() => profile.name,
() => markdownStrippedBio,
false,
getOrgFullOrigin(entity.orgSlug ?? null)
getOrgFullOrigin(entity.orgSlug ?? null),
`/${decodeParams(params).user}`
);

return {
Expand Down
10 changes: 7 additions & 3 deletions apps/web/app/(use-page-wrapper)/apps/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { notFound } from "next/navigation";
import { z } from "zod";

import { getStaticProps } from "@lib/apps/[slug]/getStaticProps";
import { decodeParams } from "@lib/buildLegacyCtx";

import AppView from "~/apps/[slug]/slug-view";

Expand All @@ -12,7 +13,7 @@ const paramsSchema = z.object({
});

export const generateMetadata = async ({ params }: _PageProps) => {
const p = paramsSchema.safeParse(params);
const p = paramsSchema.safeParse(decodeParams(params));

if (!p.success) {
return notFound();
Expand All @@ -28,12 +29,15 @@ export const generateMetadata = async ({ params }: _PageProps) => {
return await generateAppMetadata(
{ slug: logo, name, description },
() => name,
() => description
() => description,
undefined,
undefined,
`/apps/${p.data.slug}`
);
};

async function Page({ params }: _PageProps) {
const p = paramsSchema.safeParse(params);
const p = paramsSchema.safeParse(decodeParams(params));

if (!p.success) {
return notFound();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { z } from "zod";

import { AppCategories } from "@calcom/prisma/enums";

import { decodeParams } from "@lib/buildLegacyCtx";

import InstalledApps from "~/apps/installed/[category]/installed-category-view";

const querySchema = z.object({
Expand All @@ -19,7 +21,7 @@ export const generateMetadata = async () => {
};

const InstalledAppsWrapper = async ({ params }: PageProps) => {
const parsedParams = querySchema.safeParse(params);
const parsedParams = querySchema.safeParse(decodeParams(params));

if (!parsedParams.success) {
redirect("/apps/installed/calendar");
Expand Down
5 changes: 4 additions & 1 deletion apps/web/app/(use-page-wrapper)/apps/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import AppsPage from "~/apps/apps-view";
export const generateMetadata = async () => {
return await _generateMetadata(
(t) => t("app_store"),
(t) => t("app_store_description")
(t) => t("app_store_description"),
undefined,
undefined,
"/apps"
);
};

Expand Down
49 changes: 37 additions & 12 deletions apps/web/app/_utils.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { type TFunction } from "i18next";
import i18next from "i18next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import { headers } from "next/headers";
import { cookies, headers } from "next/headers";

import { getLocale } from "@calcom/features/auth/lib/getLocale";
import type { AppImageProps, MeetingImageProps } from "@calcom/lib/OgImages";
import { constructAppImage, constructGenericImage, constructMeetingImage } from "@calcom/lib/OgImages";
import { IS_CALCOM, WEBAPP_URL, APP_NAME, SEO_IMG_OGIMG, CAL_URL } from "@calcom/lib/constants";
Expand All @@ -11,6 +12,8 @@ import { truncateOnWord } from "@calcom/lib/text";
//@ts-expect-error no type definitions
import config from "@calcom/web/next-i18next.config";

import { buildLegacyRequest } from "@lib/buildLegacyCtx";

const i18nInstanceCache: Record<string, any> = {};

const createI18nInstance = async (locale: string, ns: string) => {
Expand Down Expand Up @@ -44,7 +47,7 @@ export const getTranslate = async () => {
const headersList = await headers();
// If "x-locale" does not exist in header,
// ensure that config.matcher in middleware includes the page you are testing
const locale = headersList.get("x-locale");
const locale = await getLocale(buildLegacyRequest(headersList, cookies()));
const t = await getTranslationWithCache(locale ?? "en");
return t;
};
Expand All @@ -53,12 +56,13 @@ const _generateMetadataWithoutImage = async (
getTitle: (t: TFunction<string, undefined>) => string,
getDescription: (t: TFunction<string, undefined>) => string,
hideBranding?: boolean,
origin?: string
origin?: string,
pathname?: string
) => {
const h = headers();
const pathname = h.get("x-pathname") ?? "";
const canonical = buildCanonical({ path: pathname, origin: origin ?? CAL_URL });
const locale = h.get("x-locale") ?? "en";
const _pathname = pathname ?? "";
const canonical = buildCanonical({ path: _pathname, origin: origin ?? CAL_URL });
const locale = (await getLocale(buildLegacyRequest(h, cookies()))) ?? "en";
const t = await getTranslationWithCache(locale);

const title = getTitle(t);
Expand Down Expand Up @@ -86,9 +90,16 @@ export const _generateMetadata = async (
getTitle: (t: TFunction<string, undefined>) => string,
getDescription: (t: TFunction<string, undefined>) => string,
hideBranding?: boolean,
origin?: string
origin?: string,
pathname?: string
) => {
const metadata = await _generateMetadataWithoutImage(getTitle, getDescription, hideBranding, origin);
const metadata = await _generateMetadataWithoutImage(
getTitle,
getDescription,
hideBranding,
origin,
pathname
);
const image =
SEO_IMG_OGIMG +
constructGenericImage({
Expand All @@ -110,9 +121,16 @@ export const generateMeetingMetadata = async (
getTitle: (t: TFunction<string, undefined>) => string,
getDescription: (t: TFunction<string, undefined>) => string,
hideBranding?: boolean,
origin?: string
origin?: string,
pathname?: string
) => {
const metadata = await _generateMetadataWithoutImage(getTitle, getDescription, hideBranding, origin);
const metadata = await _generateMetadataWithoutImage(
getTitle,
getDescription,
hideBranding,
origin,
pathname
);
const image = SEO_IMG_OGIMG + constructMeetingImage(meeting);

return {
Expand All @@ -129,9 +147,16 @@ export const generateAppMetadata = async (
getTitle: (t: TFunction<string, undefined>) => string,
getDescription: (t: TFunction<string, undefined>) => string,
hideBranding?: boolean,
origin?: string
origin?: string,
pathname?: string
) => {
const metadata = await _generateMetadataWithoutImage(getTitle, getDescription, hideBranding, origin);
const metadata = await _generateMetadataWithoutImage(
getTitle,
getDescription,
hideBranding,
origin,
pathname
);

const image = SEO_IMG_OGIMG + constructAppImage({ ...app, description: metadata.description });

Expand Down
2 changes: 1 addition & 1 deletion apps/web/lib/buildLegacyCtx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const buildLegacyCookies = (cookies: ReadonlyRequestCookies) => {
return createProxifiedObject(cookiesObject);
};

function decodeParams(params: Params): Params {
export function decodeParams(params: Params): Params {
return Object.entries(params).reduce((acc, [key, value]) => {
// Handle array values
if (Array.isArray(value)) {
Expand Down
Loading
Loading