@@ -13,7 +13,6 @@ import { CookieConsent } from "../components/CookieConsent";
1313import { DATADOG_APPLICATION_ID , DATADOG_CLIENT_TOKEN , ENVIRONMENT_CONTEXT , SITE_BREAKPOINTS } from "../constants" ;
1414import { DarkModeContext } from "../context/DarkModeContext" ;
1515import { PreviewThemeContext } from "../context/PreviewThemeContext" ;
16- import { logger } from "../functions-utils/logger" ;
1716import { ValidThemeName , themeCookieKey , useDarkMode } from "../hooks/useDarkMode" ;
1817import * as gtag from "../lib/gtag" ;
1918import { SimpleStorage } from "../utils/SimpleStorage" ;
@@ -28,9 +27,8 @@ interface AppPageProps {
2827const App = ( { Component, pageProps, serverThemeCookie } : AppProps & AppPageProps ) : React . ReactElement => {
2928 const cookieTheme : ValidThemeName =
3029 serverThemeCookie || ( parseCookies ( ) [ themeCookieKey ] as ValidThemeName ) || "twilio" ;
31-
3230 // eslint-disable-next-line no-console
33- console . log ( { cookieTheme , serverThemeCookie , clientCookie : parseCookies ( ) } ) ;
31+ console . log ( { serverThemeCookie , cookieTheme , clientCookie : parseCookies ( ) } ) ;
3432 const router = useRouter ( ) ;
3533 const localStorageKey = "cookie-consent-accepted" ;
3634 const [ theme , toggleMode , componentMounted ] = useDarkMode ( cookieTheme ) ;
@@ -123,7 +121,7 @@ const App = ({ Component, pageProps, serverThemeCookie }: AppProps & AppPageProp
123121 </ >
124122 ) }
125123 < Theme . Provider
126- theme = { serverThemeCookie ? serverThemeCookie : theme }
124+ theme = { theme }
127125 customBreakpoints = { SITE_BREAKPOINTS }
128126 disableAnimations = { inCypress ( ) }
129127 cacheProviderProps = { { key : "next" } }
@@ -142,16 +140,15 @@ const App = ({ Component, pageProps, serverThemeCookie }: AppProps & AppPageProp
142140App . getInitialProps = async ( context : AppContext ) : Promise < AppPageProps & AppInitialProps > => {
143141 const ctx = await NextApp . getInitialProps ( context ) ;
144142 const cookies = context . ctx . req ?. headers ?. cookie ;
143+ const responseCookie = context . ctx ?. res ?. getHeader ( themeCookieKey ) ;
145144
146- logger . info ( { cookies, clientCookie : parseCookies ( ) } ) ;
147-
148- // eslint-disable-next-line no-console
149- console . log ( context . ctx . req ) ;
150145 if ( cookies ) {
151146 const cookiestring = new RegExp ( `${ themeCookieKey } =[^;]+` ) . exec ( cookies ) ;
152147 const decodedString = decodeURIComponent ( cookiestring ? cookiestring . toString ( ) . replace ( / ^ [ ^ = ] + ./ , "" ) : "" ) ;
153148
154149 return { ...ctx , serverThemeCookie : decodedString as ValidThemeName } ;
150+ } else if ( responseCookie ) {
151+ return { ...ctx , serverThemeCookie : responseCookie as ValidThemeName } ;
155152 }
156153
157154 return { ...ctx } ;
0 commit comments