11import type { ReadonlyURLSearchParams } from "next/navigation" ;
2+ import { z } from "zod" ;
23
34import { EmbedTheme } from "@calcom/features/embed/lib/constants" ;
45
@@ -92,13 +93,28 @@ export function getThemeProviderProps({
9293 searchParams : ReadonlyURLSearchParams | null ;
9394} ) {
9495 const isBookingPage = props . isBookingPage ;
95-
9696 const themeSupport = isBookingPage
9797 ? ThemeSupport . Booking
9898 : props . isThemeSupported === false
9999 ? ThemeSupport . None
100100 : ThemeSupport . App ;
101101
102+ const themeQueryParam = searchParams ?. get ( "theme" ) ?? "" ;
103+ const themeParsed = z . enum ( [ "light" , "dark" , "system" , "auto" ] ) . safeParse ( themeQueryParam ) ;
104+ const isWrongThemeValue = themeQueryParam . length > 0 && ! themeParsed . success ;
105+ const forcedTheme = themeSupport === ThemeSupport . None || isWrongThemeValue ? "light" : undefined ;
106+ if ( forcedTheme ) {
107+ return {
108+ key : "forcedThemeKey" ,
109+ storageKey : "forcedThemeKey" ,
110+ forcedTheme,
111+ attribute : "class" ,
112+ nonce : props . nonce ,
113+ enableColorScheme : false ,
114+ enableSystem : themeSupport !== ThemeSupport . None ,
115+ } ;
116+ }
117+
102118 const isBookingPageThemeSupportRequired = themeSupport === ThemeSupport . Booking ;
103119 const themeBasis = pathname ? getUniqueIdentifierForBookingPage ( { pathname } ) : null ;
104120 const isThemeBasisRequired = isBookingPageThemeSupportRequired || isEmbedMode ;
@@ -109,8 +125,6 @@ export function getThemeProviderProps({
109125 }
110126
111127 const appearanceIdSuffix = themeBasis ? `:${ themeBasis } ` : "" ;
112- const forcedTheme = themeSupport === ThemeSupport . None ? "light" : undefined ;
113- const themeQueryParam = searchParams ?. get ( "theme" ) ;
114128 const embedExplicitlySetThemeSuffix =
115129 isEmbedMode && themeQueryParam && themeQueryParam !== EmbedTheme . auto ? `:${ themeQueryParam } ` : "" ;
116130
@@ -126,8 +140,6 @@ export function getThemeProviderProps({
126140
127141 const themeProviderProps = {
128142 storageKey,
129- // Can force a theme through this, no matter what system preference is or storage value is
130- forcedTheme,
131143 nonce : props . nonce ,
132144 enableColorScheme : false ,
133145 // Enables theme switching based on system preference if true
0 commit comments