@@ -10,6 +10,9 @@ import {
1010import { wrapCreateRootRouteWithSentry } from "@sentry/tanstackstart-react" ;
1111import appCss from "~/styles/app.css?url" ;
1212import { seo } from "~/lib/seo" ;
13+ import { ThemeProvider , useTheme } from "~/components/theme-provider" ;
14+ import { ThemeToggle } from "~/components/theme-toggle" ;
15+ import { themeQuery } from "~/lib/queries" ;
1316
1417export const Route = wrapCreateRootRouteWithSentry (
1518 createRootRouteWithContext < {
@@ -40,31 +43,47 @@ export const Route = wrapCreateRootRouteWithSentry(
4043 } ,
4144 ] ,
4245 } ) ,
46+ loader : ( { context } ) => {
47+ context . queryClient . ensureQueryData ( themeQuery ) ;
48+ } ,
4349 component : RootComponent ,
4450 notFoundComponent : DefaultGlobalNotFound ,
4551} ) ;
4652
4753function RootComponent ( ) {
4854 return (
49- < RootDocument >
50- < Outlet />
51- </ RootDocument >
55+ < ThemeProvider >
56+ < RootDocument >
57+ < Outlet />
58+ </ RootDocument >
59+ </ ThemeProvider >
5260 ) ;
5361}
5462
5563function RootDocument ( { children } : Readonly < { children : React . ReactNode } > ) {
64+ const { theme } = useTheme ( ) ;
65+
5666 return (
57- < html >
67+ < html className = { theme } suppressHydrationWarning >
5868 < head >
5969 < HeadContent />
60- < script
61- defer
62- src = { import . meta. env . VITE_ANALYTICS_SCRIPT }
63- data-website-id = { import . meta. env . VITE_ANALYTICS_WEBSITE_ID }
64- > </ script >
70+ { import . meta. env . VITE_ANALYTICS_SCRIPT &&
71+ import . meta. env . VITE_ANALYTICS_WEBSITE_ID && (
72+ < script
73+ defer
74+ src = { import . meta. env . VITE_ANALYTICS_SCRIPT }
75+ data-website-id = { import . meta. env . VITE_ANALYTICS_WEBSITE_ID }
76+ > </ script >
77+ ) }
6578 </ head >
6679 < body >
6780 { children }
81+
82+ { /* Theme Toggle - Fixed position in top-right corner */ }
83+ < div className = "fixed top-4 right-4 z-50" >
84+ < ThemeToggle />
85+ </ div >
86+
6887 < Scripts />
6988 </ body >
7089 </ html >
0 commit comments