@@ -17,6 +17,13 @@ import {
1717import { ReactQueryDevtools } from '@tanstack/react-query-devtools' ;
1818
1919import { IS_LOCAL_MODE } from '@/config' ;
20+ import {
21+ DEFAULT_FONT_VAR ,
22+ DEFAULT_MANTINE_FONT ,
23+ FONT_VAR_MAP ,
24+ MANTINE_FONT_MAP ,
25+ } from '@/config/fonts' ;
26+ import { ibmPlexMono , inter , roboto , robotoMono } from '@/fonts' ;
2027import { ThemeWrapper } from '@/ThemeWrapper' ;
2128import { useConfirmModal } from '@/useConfirm' ;
2229import { QueryParamProvider as HDXQueryParamProvider } from '@/useQueryParam' ;
@@ -61,6 +68,9 @@ export default function MyApp({ Component, pageProps }: AppPropsWithLayout) {
6168 const confirmModal = useConfirmModal ( ) ;
6269 const background = useBackground ( userPreferences ) ;
6370
71+ const selectedMantineFont =
72+ MANTINE_FONT_MAP [ userPreferences . font ] || DEFAULT_MANTINE_FONT ;
73+
6474 // port to react query ? (needs to wrap with QueryClientProvider)
6575 useEffect ( ( ) => {
6676 if ( IS_LOCAL_MODE ) {
@@ -96,10 +106,27 @@ export default function MyApp({ Component, pageProps }: AppPropsWithLayout) {
96106 } , [ ] ) ;
97107
98108 useEffect ( ( ) => {
99- // TODO: Remove after migration to Mantine
100- document . body . style . fontFamily = userPreferences . font
101- ? `"${ userPreferences . font } ", sans-serif`
102- : '"IBM Plex Mono"' ;
109+ // Apply font classes to html element for CSS variable resolution.
110+ // Although _document.tsx sets these server-side, they must be re-applied client-side
111+ // during hydration to ensure CSS variables are available for dynamic font switching.
112+ // This is critical for the --app-font-family CSS variable to work across all components.
113+ if ( typeof document !== 'undefined' ) {
114+ const fontClasses = [
115+ ibmPlexMono . variable ,
116+ robotoMono . variable ,
117+ inter . variable ,
118+ roboto . variable ,
119+ ] ;
120+ document . documentElement . classList . add ( ...fontClasses ) ;
121+ }
122+ } , [ ] ) ;
123+
124+ useEffect ( ( ) => {
125+ // Update CSS variable for global font cascading
126+ if ( typeof document !== 'undefined' ) {
127+ const fontVar = FONT_VAR_MAP [ userPreferences . font ] || DEFAULT_FONT_VAR ;
128+ document . documentElement . style . setProperty ( '--app-font-family' , fontVar ) ;
129+ }
103130 } , [ userPreferences . font ] ) ;
104131
105132 const getLayout = Component . getLayout ?? ( page => page ) ;
@@ -124,7 +151,7 @@ export default function MyApp({ Component, pageProps }: AppPropsWithLayout) {
124151 < QueryParamProvider adapter = { NextAdapter } >
125152 < QueryClientProvider client = { queryClient } >
126153 < ThemeWrapper
127- fontFamily = { userPreferences . font }
154+ fontFamily = { selectedMantineFont }
128155 colorScheme = { userPreferences . theme === 'dark' ? 'dark' : 'light' }
129156 >
130157 { getLayout ( < Component { ...pageProps } /> ) }
0 commit comments