Skip to content

Commit 150e93d

Browse files
fix: Add /router to isBookingPages to prevent 500 error on customPageMessage redirect (calcom#25522)
* Add /router to isBookingPages * Remove Dynamic Posthog Provider from AppProvider.tsx because that is only used by the pages router, and the pages router is only in use by the /router endpoint, which is a booking page and we havent implemented corresponding GeoProvider support for it
1 parent 94c7bfe commit 150e93d

3 files changed

Lines changed: 33 additions & 24 deletions

File tree

apps/web/components/PageWrapper.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
* PAGES ROUTER ONLY - Used exclusively by Next.js Pages Router
3+
*
4+
* Currently only serves the /router endpoint (routing forms redirect page).
5+
* DO NOT add new features here - this file will be deprecated once we remove apps/web/pages.
6+
*
7+
* For App Router, use PageWrapperAppDir.tsx instead.
8+
*/
9+
110
"use client";
211

312
import { DefaultSeo } from "next-seo";

apps/web/lib/app-providers.tsx

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
* PAGES ROUTER ONLY - Used exclusively by Next.js Pages Router (_app.tsx)
3+
*
4+
* Currently only serves the /router endpoint (routing forms redirect page).
5+
* DO NOT add new features here - this file will be deprecated once we remove apps/web/pages.
6+
*
7+
* For App Router, use app-providers-app-dir.tsx instead.
8+
*/
9+
110
import { TooltipProvider } from "@radix-ui/react-tooltip";
211
import { dir } from "i18next";
312
import type { Session } from "next-auth";
@@ -12,7 +21,6 @@ import type { ParsedUrlQuery } from "querystring";
1221
import type { PropsWithChildren, ReactNode } from "react";
1322
import { useEffect } from "react";
1423

15-
import DynamicPostHogProvider from "@calcom/features/ee/event-tracking/lib/posthog/providerDynamic";
1624
import { OrgBrandingProvider } from "@calcom/features/ee/organizations/context/provider";
1725
import DynamicHelpscoutProvider from "@calcom/features/ee/support/lib/helpscout/providerDynamic";
1826
import DynamicIntercomProvider from "@calcom/features/ee/support/lib/intercom/providerDynamic";
@@ -53,12 +61,6 @@ export type AppProps = Omit<
5361
err?: Error;
5462
};
5563

56-
const PostHogPageView = dynamic(
57-
() => import("@calcom/features/ee/event-tracking/lib/posthog/web/PostHogPageView"),
58-
{
59-
ssr: false,
60-
}
61-
);
6264

6365
type AppPropsWithChildren = AppProps & {
6466
children: ReactNode;
@@ -134,8 +136,8 @@ const enum ThemeSupport {
134136

135137
type CalcomThemeProps = PropsWithChildren<
136138
Pick<AppProps, "router"> &
137-
Pick<AppProps["pageProps"], "themeBasis"> &
138-
Pick<AppProps["Component"], "isBookingPage" | "isThemeSupported">
139+
Pick<AppProps["pageProps"], "themeBasis"> &
140+
Pick<AppProps["Component"], "isBookingPage" | "isThemeSupported">
139141
>;
140142
const CalcomThemeProvider = (props: CalcomThemeProps) => {
141143
// Use namespace of embed to ensure same namespaced embed are displayed with same theme. This allows different embeds on the same website to be themed differently
@@ -209,8 +211,8 @@ function getThemeProviderProps({
209211
? ThemeSupport.Booking
210212
: // if isThemeSupported is explicitly false, we don't use theme there
211213
props.isThemeSupported === false
212-
? ThemeSupport.None
213-
: ThemeSupport.App;
214+
? ThemeSupport.None
215+
: ThemeSupport.App;
214216

215217
const isBookingPageThemeSupportRequired = themeSupport === ThemeSupport.Booking;
216218
const themeBasis = props.themeBasis;
@@ -234,13 +236,13 @@ function getThemeProviderProps({
234236

235237
const storageKey = isEmbedMode
236238
? // Same Namespace, Same Organizer but different themes would still work seamless and not cause theme flicker
237-
// Even though it's recommended to use different namespaces when you want to theme differently on the same page but if the embeds are on different pages, the problem can still arise
238-
`embed-theme-${embedNamespace}${appearanceIdSuffix}${embedExplicitlySetThemeSuffix}`
239+
// Even though it's recommended to use different namespaces when you want to theme differently on the same page but if the embeds are on different pages, the problem can still arise
240+
`embed-theme-${embedNamespace}${appearanceIdSuffix}${embedExplicitlySetThemeSuffix}`
239241
: themeSupport === ThemeSupport.App
240-
? "app-theme"
241-
: isBookingPageThemeSupportRequired
242-
? `booking-theme${appearanceIdSuffix}`
243-
: undefined;
242+
? "app-theme"
243+
: isBookingPageThemeSupportRequired
244+
? `booking-theme${appearanceIdSuffix}`
245+
: undefined;
244246

245247
return {
246248
storageKey,
@@ -307,12 +309,7 @@ const AppProviders = (props: AppPropsWithChildren) => {
307309

308310
return (
309311
<>
310-
<DynamicHelpscoutProvider>
311-
<DynamicPostHogProvider>
312-
<PostHogPageView />
313-
{RemainingProviders}
314-
</DynamicPostHogProvider>
315-
</DynamicHelpscoutProvider>
312+
<DynamicHelpscoutProvider>{RemainingProviders}</DynamicHelpscoutProvider>
316313
</>
317314
);
318315
};

apps/web/lib/hooks/useIsBookingPage.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { usePathname } from "next/navigation";
22

33
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
4-
4+
// TODO: This approach of checking booking page isn't correct.
5+
// app.cal.com/rick is a booking page but useIsBookingPage won't return true. This is because all unregistered router in Next.js could technically be a booking page throw catch all routes.
6+
// The only way to confirm it is by actually checking if we actually rendered a booking route.
57
export default function useIsBookingPage(): boolean {
68
const pathname = usePathname();
79
const isBookingPage = [
@@ -13,6 +15,7 @@ export default function useIsBookingPage(): boolean {
1315
"/d", // Private Link of booking page
1416
"/apps/routing-forms/routing-link", // Routing Form page
1517
"/forms/", // Rewrites to /apps/routing-forms/routing-link
18+
"/router", // Headless router page - Loads as a page when redirect type is customPageMessage
1619
].some((route) => pathname?.startsWith(route));
1720
const isBookingsListPage = ["/upcoming", "/unconfirmed", "/recurring", "/cancelled", "/past"].some(
1821
(route) => pathname?.endsWith(route)

0 commit comments

Comments
 (0)