fix: theme search param crashing booking page (#21120)

* fix

* fix
This commit is contained in:
Benny Joo
2025-05-06 00:31:40 +00:00
committed by GitHub
parent d4a3894a9e
commit f9488a1866
2 changed files with 19 additions and 7 deletions
@@ -52,8 +52,8 @@ describe("getThemeProviderProps", () => {
expect(result).toEqual({
...appThemeExpectedProps,
storageKey: undefined,
key: undefined,
storageKey: "forcedThemeKey",
key: "forcedThemeKey",
forcedTheme: "light",
enableSystem: false,
});
+17 -5
View File
@@ -1,4 +1,5 @@
import type { ReadonlyURLSearchParams } from "next/navigation";
import { z } from "zod";
import { EmbedTheme } from "@calcom/features/embed/lib/constants";
@@ -92,13 +93,28 @@ export function getThemeProviderProps({
searchParams: ReadonlyURLSearchParams | null;
}) {
const isBookingPage = props.isBookingPage;
const themeSupport = isBookingPage
? ThemeSupport.Booking
: props.isThemeSupported === false
? ThemeSupport.None
: ThemeSupport.App;
const themeQueryParam = searchParams?.get("theme") ?? "";
const themeParsed = z.enum(["light", "dark", "system", "auto"]).safeParse(themeQueryParam);
const isWrongThemeValue = themeQueryParam.length > 0 && !themeParsed.success;
const forcedTheme = themeSupport === ThemeSupport.None || isWrongThemeValue ? "light" : undefined;
if (forcedTheme) {
return {
key: "forcedThemeKey",
storageKey: "forcedThemeKey",
forcedTheme,
attribute: "class",
nonce: props.nonce,
enableColorScheme: false,
enableSystem: themeSupport !== ThemeSupport.None,
};
}
const isBookingPageThemeSupportRequired = themeSupport === ThemeSupport.Booking;
const themeBasis = pathname ? getUniqueIdentifierForBookingPage({ pathname }) : null;
const isThemeBasisRequired = isBookingPageThemeSupportRequired || isEmbedMode;
@@ -109,8 +125,6 @@ export function getThemeProviderProps({
}
const appearanceIdSuffix = themeBasis ? `:${themeBasis}` : "";
const forcedTheme = themeSupport === ThemeSupport.None ? "light" : undefined;
const themeQueryParam = searchParams?.get("theme");
const embedExplicitlySetThemeSuffix =
isEmbedMode && themeQueryParam && themeQueryParam !== EmbedTheme.auto ? `:${themeQueryParam}` : "";
@@ -126,8 +140,6 @@ export function getThemeProviderProps({
const themeProviderProps = {
storageKey,
// Can force a theme through this, no matter what system preference is or storage value is
forcedTheme,
nonce: props.nonce,
enableColorScheme: false,
// Enables theme switching based on system preference if true