diff --git a/gatsby-browser.tsx b/gatsby-browser.tsx index 4b57943ba5..60e613143d 100644 --- a/gatsby-browser.tsx +++ b/gatsby-browser.tsx @@ -6,6 +6,7 @@ import { PostHogProvider } from 'posthog-js/react'; import posthog from 'posthog-js'; import UserContextWrapper from './src/contexts/user-context/wrap-with-provider'; +import { ThemeProvider } from './src/contexts/theme-context'; import { useSiteMetadata } from './src/hooks/use-site-metadata'; const onClientEntry: GatsbyBrowser['onClientEntry'] = () => { @@ -56,9 +57,11 @@ const InsightsWrapper = ({ children }) => { export const wrapRootElement = ({ element }) => { return ( - - - + + + + + ); }; diff --git a/gatsby-ssr.tsx b/gatsby-ssr.tsx index c34c350f36..a7e7c24e50 100644 --- a/gatsby-ssr.tsx +++ b/gatsby-ssr.tsx @@ -1,10 +1,15 @@ import React from 'react'; import type { GatsbySSR } from 'gatsby'; import { getSandpackCssText } from '@codesandbox/sandpack-react'; +import { THEME_NO_FLASH_SCRIPT } from './src/utilities/theme'; const onRenderBody: GatsbySSR['onRenderBody'] = ({ setHeadComponents }) => { const inlineScripts: React.ReactNode[] = []; + // Set the theme class on before first paint to avoid a flash of the + // wrong theme. Runs first so the class is present before any styles apply. + inlineScripts.push(